Questions from the material presented in this lecture

Size: px
Start display at page:

Download "Questions from the material presented in this lecture"

Transcription

1 Advanced Data Structures Questions from the material presented in this lecture January 8, 2015 This material illustrates the kind of exercises and questions you may get at the final colloqium. L1. Introduction. Structures for graphs You should be able to indicate The main data structures for graphs, Algorithms to test connectivity in graphs represented by these data structures, What is the definition of matrix A of a graph with adjacency matrix A? How can we compute A iteratively and recursively? The runtime complexity for an algorithm that computes A? The purpose of Warshall s algorithm the pseudo-code and its runtime complexity The runtime complexity of various algorithms. Typical questions 1. What is the worst-case running time for the following procedure as a function of n: procedure mystery(n : integer) var i, j, k : integer begin for i := 1 to n do for j := i + 1 to n do for k := 1 to j do print (i + j k) end 1

2 Answer: The runtime complexity of this function is proportional to the number of executions of the print operation, which is n n i=1 j=i+1 k=1 j 1 n n i=1 j=1 k=1 n 1 = n 3. Thus, the runtime complexity of this procedure is O(n 3 ). 2. Let A[1..n] be an array of floating point values. (a) Define a procedure amplitude(a) which computes the maximum difference between two elements of the array A. (b) Give, using the big oh notation, the worst-case running time T (n) of the procedure defined by you. Answer: Note that the desired value is the difference between the maximum and minimum element of the given array, thus it can be computed with the following pseudocode: float amplitude(float A[1..n]) float m, M; m = A[1]; M = A[1]; i = 2; while i <= n if A[i] < m then m = A[i] if A[i] > M then M = A[i] i = i + 1 return M m T (n) is proportional to the number of times we execute the while loop, which is n. Thus T (n) = O(n). 3. Consider list elements with the following structure (in C++): struct node { int data; node* next; Write down the (pseudo)code for the function node* inverse(node* x) which takes as input a pointer x to the first element of a simply linked list with n elements, and does the following: It inverts the list in-place, by changing the next pointers of its nodes. It returns a pointer y to the first element of the reverted list. 2

3 x... k 1 k 2 k n... k 1 k 2 k n y Answer: The inversion can be carried out in one traversal of the list from left to right. At every step of the traversal, we maintain 2 pointers: y is a pointer to the node which is currently visited. p is a pointer to the node before y, which is the head of the list reverted so far. Initially, y = x, and p is the null pointer. node* inverse(node* x) { node* y, p, tmp; y = x; p = 0; while(y->next!= 0) { tmp = y->next; y->next = p; p = y; y = tmp; // y->next is null here y->next = p; return y; The runtime complexity of this implementation is proportional with the number of executions of the while loop, which is the length of the list with head x. Thus, the runtime complexity is O(n). L2: Single-source shortest paths This lecture was about Dijkstra algorithm and about Bellman-Ford algorithm. Indicate the pseudocode an the runtime complexity of these algorithms. Indicate the differences between these algorithms. What is the purpose of the relaxation method? Indicate its psudocode and he meaning of the auxiliary data structures on which it acts. Illustrate the outcome of a while loop of Dijkstra s algorithm on some particular configuration of a weighted graph. For example, assume the following digraph with upper bounds d[v] and predecessors π[v] of nodes as shown in the figure: 3

4 3 d:3 u π:s d: v π:s d:0 s π:undef d: x π:s d: y π:s Draw the outcome of relaxing all edges which leave node u. L3: Red-black trees 1. What is a balanced red-black tree? Which are the red-black properties that must be satisfied? 2. What operations are well supported by Red-Black trees, and what is their runtime complexity? 3. The operations LeftRotate(y) and RightRotate(x) transform a node in an RB-tree as depicted in the following picture: y RightRotate(y) x x γ LeftRotate(x) α y α β β γ where the nodes referred by x and y may appear anywhere in the red-black tree T. Assume a node of an RB-tree is an instance of the C++ class enum rbcolor { RED, BLACK ; class rbnode { public: int key; rbnode *left; // pointer to left child rbnode *right; // pointer to right child rbnode *p; // pointer to parent rbnode color; // node color (a) Write down the C++ code for the method rbtree* leftrotate(rbtree *x) (Note that in this case, we must have y=x.right) (b) Write down the C++ code for the method 4

5 rbtree* rightrotate(rbtree *y) Answer: (Note that in this case, we must have x=y.left) rbnode* rightrotate(rbnode* y) { rbnode* x = y->left; rbnode *alpha = x->left, *beta = x->right, *gamma = y->right; x->p = y->p; y->p = x; x->left = alpha; y->left = beta; y->right = gamma; // reset the parent of gamma, if gamma!= null if (beta!= null) beta->p = y; return x; The method leftrotate can be defined similarly. 4. Consider the following trees: (a) (b) (c) (d) (e) 1. Which trees satisfy the red-black properties and which do not? For the trees which do not satisfy the red-black properties, indicate which are not satisfied. 5

6 2. For the trees which satisfy the red-black properties, indicate the black-height of their root. L4: B-trees 1. Give the formal definition of a B-tree with minimum degree t. Answer: A B-tree with minimum degree t is a rooted tree whose structure can be described in C++ as follows: The nodes are structures of the following kind: struct node { int n; // the number of keys currently stored in this node int key[2 t 1]; // array that stores the keys in this node bool leaf; // true if this node has no children, and false otherwise node* c[2 t]; // array of pointers to its children The following properties must be satisfied by every node x: If x is a non-leaf node with n keys (that is, x.n==n and x.leaf ==false), then it has n+1 children and k 0 x.key[0] k 1 x.key[1]... x.key[n 1] k n whenever k i is any key stored in the subtree pointed to by x.c[i]. All leaves have the same height h, which is the height of the tree. If x is not the root of the tree, then x.n t 1. (Every node other than the root must have at least t 1 keys) x.n 2 t 1. (Every node other than the root must have at most 2 t 1 keys) 2. What operations can be performed efficiently with B-trees and RB-trees? What is the complexity of these operations? Answer: RB-trees are data structures design to support the efficient execution of the following operations on a dynamic set S with n elements: Search(S, k): returns a pointer p to an element in S such that p x = k, or Nil if no such element exists. Minimum(S): returns a pointer to the element of S whose key is minimum, or Nil is S has no elements. Maximum(S): returns a pointer to the element of S whose key is maximum, or Nil is S has no elements. Successor(S, x): returns the next element larger than x in S, or Nil if x is the maximum element. Predecessor(S, x): returns the next element smaller than x in S, or Nil if x is the minimum element.

7 Insert(S, p): augment S with the element pointed to by p. If p is Nil, do nothing. Delete(S, p): remove the element pointed to by p from S. If p is Nil, do nothing. The runtime complexity of all these operations is O(log n). B-trees are data structures designed to support the efficient execution of the following operations: Search(x, k): searches in the tree with root pointed by x, for the existence of a node that contains key k. Runtime complexity is O(t log t n). Create(): creates an empty tree. Runtime complexity is O(1). Insert(T, k) : insert key k in tree with root x. Runtime complexity is O(t log t n). Delete(x, k): delete key k from tree with root x. Runtime complexity is O(t log t n). 3. Draw a B-tree with minimal degree t = 3 whose nodes contain the keys 1, 2, 3, 4, 5,, 8, 9, 11, 1, 24. Answer: First, note that a node of such a B-tree can contain at most 2 t 1 = 5 keys, and all nodes except the root must contain at least t 1 = 2 keys. For example, we can have What is the minimum number of nodes in a B-tree with height 4 and minimum degree t = 10? What is the maximum number of nodes in a B-tree with height 4 and minimum degree t = 10? Answer: A B-tree with minimum degree t = 10 and depth 4 has minimum number of nodes if the root has 2 children, and the nodes at depths 1, 2, and 3 have minimum number of children. The minimum number of children of a non-root non-leaf node is t = 10. Thus the minimum number of nodes in such a B-tree is t + 2 t t 3 = 2223 where every i-th summand represents the number of nodes at depth i in the B-tree. Note also that the minimal number of keys stored in such a minimal B-tree can be computed as follows: (t 1) + 2 t (t 1) + 2 t 2 (t 1) + 2 t 3 (t 1) =

8 A B-tree with minimum degree t = 10 and depth 4 has maximum number of nodes if the nodes at depths 0, 1, 2, and 3 have maximum number of children, that is, 2 t = 20. Thus the maximum number of nodes in such a B-tree is t + (2 t) 2 + (2 t) 3 + (2 t) 4 = where every i-th summand represents the number of nodes at depth i in the B-tree. Note also that the maximum number of keys stored on such a maximal subtree is (2 t 1) = , and this happens when every node contains 2 t 1 = 19 keys. 5. Explain how to search for a node with key k in a B-tree. What is the runtime complexity of this operation?. The operation B-Tree-Split-Child(x, i, y) is sometimes performed in a B-tree T with minimum degree t, when x is a nonfull internal node of T (that is, x contains less than 2 t 1 keys), and i is an index such that y is the i + 1-th child of x, and y is a full node (that is, y contains 2 t 1 keys). In this case, the median key of y is moved into the proper place in x, and the remaining keys of y are split in 2 halves to be stored in 2 new children of x. Illustrate the structure of the B-tree after performing B- Tree-Split-Child(x, 2, y) for the nodes x and y depicted below, where t = 4: x x->key[0] x->key[1] x->key[2] x->key[3] y L5: Binary heaps 1. What is a binary heap? How to compute the parent, left child, and right child of a node with index i in a binary heap? Write down the heap property of binary heap. Answer: A binary heap is a data structure made of an array A of objects together with two special attributes: (a) A.length: the length, or capacity, of the array. (b) A.heap size: the actual number of elements in the heap 8

9 such that A.heap size A.length and the heap elements are stored, from left to right, in the array A. Such a binary head represents a complete binary array with A.heap size nodes, in which The parent of the element stored { in A[i] is the element stored in (i 1)/2 if i 0 A[parent(i)] where parent(i) = 1 if i = 0 The left child of the element stored in A[i] is the element stored in A[left(i)] where left(i) = 2 i + 1. The right child of the element stored in A[i] is the element stored in A[right(i)] where right(i) = 2 i + 2. and must satisfy the following property (called the heap property) for all i 0: A[parent(i)] A[i]. Intuitively, this means that, in the binary tree representation of the heap, the key of any node is larger than the keys of its children. 2. What operations can be performed efficiently with binary heaps? What is the complexity of these operations? 3. You should be able to write down the array representation of a binary heap depicted as a binary array, and vice versa. 4. Is the following binary tree a valid representation of a binary heap? Explain your answer. Answer: No, because the heap property is not satisfied: the key of the node with index 0 is smaller then the keys of its children. 5. The operation Heapify(A, i) is defined for an array A and an index i with the following properties: the subtrees rooted at left(i) and right(i) are binary heaps, the subtree rooted at i may not be a binary heap, and it rearranges the elements of A until it becomes a binary heap. Illustrate the binary heap produced by Heapify(A, i) for the array depicted below and i = 0. 9

10 Answer: The left and right subtrees of node with index 0 are binary heaps, but A is not a binary heap. Heapify(A, 0) will push the key of the node with index 0 downwards until the tree becomes a binomial heap: Explain how can we use binary heaps and Heapify() to sort an array A with n elements in O(n log 2 n) time. Answer: First, the elements of the array A are inserted, one by one, in a binary heap with heap size = length = n. We name this operation BuildHeap(A). This operation takes O(n) time. Afterwards, we repeatedly swap the maximum element A[0] with the last element A[heap size 1], reduce the heap size by 1, and ensure that the shrinked array is a binary heap by calling Heapify(A, 0). When the heap size becomes 1, A will contain the elements in increasing order. The pseudo-code of this algorithm is HeapSort(A) 1 BuildHeap(A) 2 for i := A.length 1 downto 1 3 exchange A[0] A[i] 4 A.heap size := A.heap size 1 5 Heapify(A, 0) 7. Illustrate how HeapSort performs the sorting of the elements of the array A with element values A[0] = 7, A[1] = 2, A[2] = 1, A[3] = 9, A[4] =. Answer: First, BuildHeap(A) constructs a binary heap by successively inserting the elements 7,2,1,9, into an empty heap. The initial binary heap, and its evolution during shrinking are depicted below:

11 L: Binomial heaps 1. What is a heap-ordered binomial tree? Illustrate a heap-ordered binomial tree with depth 3, and indicate some remarkable properties of binomial trees. Answer: A binomial tree is an element of the set of ordered trees {B k k N defined recursively as follows: B 0 consists of a single node. B k consists of two binomial trees B k 1 that are linked such that one of them has the other one as left child of its root. A binomial tree is heap-ordered if the key of any node is greater than or equal to the key of its parent. The following is a heap-ordered binomial tree with depth 3: Remarkable properties of binomial trees: For every binomial tree B k the following hold: (a) It has 2 k nodes. (b) It has height k. (c) There are exactly ( k i) nodes at depth i for i = 0, 1,..., k. (d) The root has degree k, which is greater than that of any other node. Moreover, if the children of the root are numbered from left to right by k 1, k 2,..., 0, then child i is the root of a subtree B i. 2. What is a binomial heap? Which operations are well supported by a binomial heap? 3. Write down a suitable C++ class for the implementation of a node in a binomial heap. Explain the meaning of every field in the class. Answer: struct bnode { bnode *p; // pointer to parent node bnode *child; // pointer to the left child of the node bnode *sibling; // pointer to the right sibling of the node int key; // the key of the node int degree; // the number of children of the node 11

12 4. Draw a binomial heap with 11 elements and the binomial heap resulted of removing its minimum element. Answer: Te root list of a binomial heap consists of binomial trees with different number of nodes, and every binomial tree contains 2 k nodes for some k N. Note that 11 = , thus we can have a binomial heap made of 3 binomial trees: the first with one element, the second with 2 elements, and the third with 8 elements. For example: H.head The following diagram does not represent a binomial heap. Indicate the binomial heap conditions which are fulfilled, and those which are violated. H.head Answer: The second tree from the root list from is not heap-ordered: the node with key 12 has a child with a smaller key.. Consider the following C++ class definition to represent nodes in a binomial heap: class bnode { public: bnode *p; // pointer to the parent bnode *child; // pointer to the left child bnode *sibling; // pointer to the right sibling int key; // key value int degree; // number of children (a) Define the method bool isbtree(bnode* t, int n) {... which returns true if t is a pointer to the root of a binomial tree B n, and false otherwise. 12

13 (b) Define the C++ method Answer bool isheapordered(bnode* t, int n) {... which returns true if t is a pointer to the root of a heap-ordered binomial tree B n, and false otherwise. (a) bool isbtree(bnode* t, int n) { if (t == 0) // t should be non-null return false; bnode* tmp = t->child; for (int i = n-1; i>=0,i--) { // check if the children of node t are B n 1,..., B 1, B 0 if (!isbtree(tmp,i)) return false; tmp = tmp->sibling; // tmp should be null here return (tmp == 0); In the worst case, this procedure is called recursively for every node in the binomial tree, thus its runtime complexity is O(N), where N is the number of nodes in the binomial tree. (b) bool isheapordered(bnode* t, int n) { if (t == 0) // t should be non-null return false; bnode* tmp = t->child; for (int i = n-1; i>=0,i--) { // check if the children of node t are B n 1,..., B 1, B 0 // and that their keys are larger than the key of t if (!(isheapordered(tmp,i) && (t->key <= tmp->key))) return false; tmp = tmp->sibling; // tmp should be null here return (tmp == 0); In the worst case, this procedure is called recursively for every node in the binomial tree, thus its runtime complexity is O(N), where N is the number of nodes in the binomial tree. 7. Suppose a binomial heap is represented by an instance of the class struct bheap { bnode* head; 13

14 (a) Define the C++ method bool isbheap(bheap* h) {... which returns true if h is an instance of a binomial heap, and false otherwise. (Note: Check that the root list of h consists of binomial trees which are heap-ordered.) (b) Define the C++ method bnode* getminimum(bheap* h) which returns a pointer to the node with minimum key in the binary heap h. (c) Define the C++ method bnode *btreemerge(btree* t1, btree* b2) which merges 2 heap-ordered binomial trees t 1 and t 2 from B n and produces a heap-ordered binomial tree from B n+1. That is the time complexity of this operation? (Note: either t 1 becomes the left child of the root of t 2, or t 2 becomes the left child of the root of t 1. The distinction is made by comparing the keys of t 1 and t 2.) L7: Fibonacci heaps and amortized analysis 1. What is a Fibonacci heap? What operations can be performed efficiently with Fibonacci heaps? 2. What is an unordered binomial tree? Indicate some interesting properties of the set U n of unordered binomial trees. 3. Draw a Fibonacci heap with 7 elements, and the Fibonacci heap that results after removing its minimum element. 4. Write down a suitable C++ class for the implementation of a node in a Fibonacci heap. Explain the meaning of every field in the class. 5. What conditions must be fulfilled by an unordered heap-ordered tree in a Fibonacci heap?. What are the differences between a binomial heap and a Fibonacci heap? 7. The following diagram does not represent a Fibonacci heap. Indicate which conditions of a Fibonacci heap are fulfilled, and which conditions are violated. 14

15 H.min Consider the following C++ class to describe nodes in a Fibonacci heap: class unode { public: bnode *p; // pointer to the parent; 0 if it has no parent bnode *child; // pointer to a child int degree; // number of children bool mark; // a boolean value int key; // key value bnode *left; // pointer to the left sibling bnode *right; // pointer to the right sibling and the following class for the representation of Fibonacci heaps: class fibheap { public: bnode *min; // pointer to the root of tree in the Fibonacci heap int n; // number of nodes in the heap Define the method int rootlistlength(fibheap h) {... which computes the length of the root list of the Fibonacci heap h. Amortized analysis 1. What is amortized analysis? Indicate 3 common techniques for amortized analysis. 2. Assume A is an 8-bit counter with A[7] = 0. The number stored in A is x := 7 k=0 A[k] 2k. (a) For what value of x is the number of bit flips of Increment(A) maximum? (b) For what values of x is the number of bit flips of Increment(A) minimum? 15

16 3. Consider the data structure consisting of a bit counter whose bits are initially all 1, together with the Decrement operation that decrements the value of the bit counter by 1. (a) Write down the pseudocode for Decrement. (b) Compute the amortized cost of Decrement with the Aggregate method. 4. What is the average number of bit flips of A[i] in a sequence of n Increment operations of a bit counter whose bits are initially all 0? 1

Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting

Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting 6331 - Algorithms, Spring 2014, CSE, OSU Lecture 2: Sorting Instructor: Anastasios Sidiropoulos January 10, 2014 Sorting Given an array of integers A[1... n], rearrange its elements so that A[1] A[2]...

More information

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?

Comparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort? So far we have studied: Comparisons Insertion Sort Merge Sort Worst case Θ(n 2 ) Θ(nlgn) Best case Θ(n) Θ(nlgn) Sorting Revisited So far we talked about two algorithms to sort an array of numbers What

More information

Lecture 3: B-Trees. October Lecture 3: B-Trees

Lecture 3: B-Trees. October Lecture 3: B-Trees October 2017 Remarks Search trees The dynamic set operations search, minimum, maximum, successor, predecessor, insert and del can be performed efficiently (in O(log n) time) if the search tree is balanced.

More information

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers

Comparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers So far we have studied: Comparisons Tree is completely filled on all levels except possibly the lowest, which is filled from the left up to a point Insertion Sort Merge Sort Worst case Θ(n ) Θ(nlgn) Best

More information

Lecture 5: Sorting Part A

Lecture 5: Sorting Part A Lecture 5: Sorting Part A Heapsort Running time O(n lg n), like merge sort Sorts in place (as insertion sort), only constant number of array elements are stored outside the input array at any time Combines

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures CMPSC 465 LECTURES 11-12 Priority Queues and Heaps Adam Smith 1 Priority Queue ADT Dynamic set of pairs (key, data), called elements Supports operations: MakeNewPQ() Insert(S,x)

More information

CS 241 Analysis of Algorithms

CS 241 Analysis of Algorithms CS 241 Analysis of Algorithms Professor Eric Aaron Lecture T Th 9:00am Lecture Meeting Location: OLB 205 Business HW4 out Due Tuesday, Nov. 5 For when should we schedule a make-up lecture? Exam: Tuesday

More information

Heapsort. Algorithms.

Heapsort. Algorithms. Heapsort Algorithms www.srijon.softallybd.com Outline Heaps Maintaining the heap property Building a heap The heapsort algorithm Priority queues 2 The purpose of this chapter In this chapter, we introduce

More information

Introduction to Algorithms 3 rd edition

Introduction to Algorithms 3 rd edition Introduction to Algorithms 3 rd edition Heapsort Mohammad Heidari Faculty of Mathematics and Computer Khansar March 6, 2017 M.Heidari (Computer Science Khansar) Introduction to Algorithms March 6, 2017

More information

Data Structures and Algorithms Week 4

Data Structures and Algorithms Week 4 Data Structures and Algorithms Week. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Week Divide and conquer Merge

More information

Heaps and Priority Queues

Heaps and Priority Queues Heaps and Priority Queues (A Data Structure Intermezzo) Frits Vaandrager Heapsort Running time is O(n lg n) Sorts in place Introduces an algorithm design technique» Create data structure (heap) to manage

More information

403: Algorithms and Data Structures. Heaps. Fall 2016 UAlbany Computer Science. Some slides borrowed by David Luebke

403: Algorithms and Data Structures. Heaps. Fall 2016 UAlbany Computer Science. Some slides borrowed by David Luebke 403: Algorithms and Data Structures Heaps Fall 20 UAlbany Computer Science Some slides borrowed by David Luebke Birdseye view plan For the next several lectures we will be looking at sorting and related

More information

Basic Data Structures and Heaps

Basic Data Structures and Heaps Basic Data Structures and Heaps David Kauchak Sorting demo (http://math.hws.edu/tmcm/java/xsortlab/) Data structures What is a data structure? Way of storing data that facilitates particular operations.

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 Amarda Shehu Lecture: Analysis of Algorithms (CS583-002) Sorting in O(n lg n) Time: Heapsort 1 Outline of Today s Class Sorting in O(n

More information

Data Structures and Algorithms Chapter 4

Data Structures and Algorithms Chapter 4 Data Structures and Algorithms Chapter. About sorting algorithms. Heapsort Complete binary trees Heap data structure. Quicksort a popular algorithm very fast on average Previous Chapter Divide and conquer

More information

Data Structures and Algorithms. Roberto Sebastiani

Data Structures and Algorithms. Roberto Sebastiani Data Structures and Algorithms Roberto Sebastiani roberto.sebastiani@disi.unitn.it http://www.disi.unitn.it/~rseba - Week 0 - B.S. In Applied Computer Science Free University of Bozen/Bolzano academic

More information

Advanced Data Structures Summary

Advanced Data Structures Summary Advanced Data Structures Summary We discussed about the following data structures and operations related to them: Binary search trees 1. What information must be stored in the nodes of a binary search

More information

Chapter 6 Heap and Its Application

Chapter 6 Heap and Its Application Chapter 6 Heap and Its Application We have already discussed two sorting algorithms: Insertion sort and Merge sort; and also witnessed both Bubble sort and Selection sort in a project. Insertion sort takes

More information

quiz heapsort intuition overview Is an algorithm with a worst-case time complexity in O(n) data structures and algorithms lecture 3

quiz heapsort intuition overview Is an algorithm with a worst-case time complexity in O(n) data structures and algorithms lecture 3 quiz data structures and algorithms 2018 09 10 lecture 3 Is an algorithm with a worst-case time complexity in O(n) always faster than an algorithm with a worst-case time complexity in O(n 2 )? intuition

More information

The Heap Data Structure

The Heap Data Structure The Heap Data Structure Def: A heap is a nearly complete binary tree with the following two properties: Structural property: all levels are full, except possibly the last one, which is filled from left

More information

Topic: Heaps and priority queues

Topic: Heaps and priority queues David Keil Data Structures 8/05 1 Topic: Heaps and priority queues The priority-queue problem The heap solution Binary trees and complete binary trees Running time of heap operations Array implementation

More information

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya

CS60020: Foundations of Algorithm Design and Machine Learning. Sourangshu Bhattacharya CS60020: Foundations of Algorithm Design and Machine Learning Sourangshu Bhattacharya Special Types of Trees Def: Full binary tree = a binary tree in which each node is either a leaf or has degree exactly

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

V Advanced Data Structures

V Advanced Data Structures V Advanced Data Structures B-Trees Fibonacci Heaps 18 B-Trees B-trees are similar to RBTs, but they are better at minimizing disk I/O operations Many database systems use B-trees, or variants of them,

More information

BM267 - Introduction to Data Structures

BM267 - Introduction to Data Structures BM267 - Introduction to Data Structures 9. Heapsort Ankara University Computer Engineering Department Bulent Tugrul BLM 267 1 (Binary) Heap Structure The heap data structure is an array organized as a

More information

Partha Sarathi Manal

Partha Sarathi Manal MA 515: Introduction to Algorithms & MA353 : Design and Analysis of Algorithms [3-0-0-6] Lecture 11 http://www.iitg.ernet.in/psm/indexing_ma353/y09/index.html Partha Sarathi Manal psm@iitg.ernet.in Dept.

More information

Heapsort. Heap data structure

Heapsort. Heap data structure Heapsort Heap data structure. Heap A (not garbage-collected storage) is a nearly complete binary tree.. Height of node = # of edges on a longest simple path from the node down to a leaf.. Height of heap

More information

18.3 Deleting a key from a B-tree

18.3 Deleting a key from a B-tree 18.3 Deleting a key from a B-tree B-TREE-DELETE deletes the key from the subtree rooted at We design it to guarantee that whenever it calls itself recursively on a node, the number of keys in is at least

More information

Lecture 6: Analysis of Algorithms (CS )

Lecture 6: Analysis of Algorithms (CS ) Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black

More information

Properties of a heap (represented by an array A)

Properties of a heap (represented by an array A) Chapter 6. HeapSort Sorting Problem Input: A sequence of n numbers < a1, a2,..., an > Output: A permutation (reordering) of the input sequence such that ' ' ' < a a a > 1 2... n HeapSort O(n lg n) worst

More information

COSC Advanced Data Structures and Algorithm Analysis Lab 3: Heapsort

COSC Advanced Data Structures and Algorithm Analysis Lab 3: Heapsort COSC 320 - Advanced Data Structures and Algorithm Analysis Lab 3: Heapsort Dr. Joe Anderson Due: 21 February 2019 1 Objectives In this lab you will focus on the following objectives: 1. Develop familiarity

More information

Data structures. Organize your data to support various queries using little time and/or space

Data structures. Organize your data to support various queries using little time and/or space Data structures Organize your data to support various queries using little time and/or space Given n elements A[1..n] Support SEARCH(A,x) := is x in A? Trivial solution: scan A. Takes time Θ(n) Best possible

More information

CSE 241 Class 17. Jeremy Buhler. October 28, Ordered collections supported both, plus total ordering operations (pred and succ)

CSE 241 Class 17. Jeremy Buhler. October 28, Ordered collections supported both, plus total ordering operations (pred and succ) CSE 241 Class 17 Jeremy Buhler October 28, 2015 And now for something completely different! 1 A New Abstract Data Type So far, we ve described ordered and unordered collections. Unordered collections didn

More information

HEAP. Michael Tsai 2017/4/25

HEAP. Michael Tsai 2017/4/25 HEAP Michael Tsai 2017/4/25 2 Array Representation of Tree Tree 2 4 1 (a) Array 1 2 3 4 5 6 7 8 9 10 16 14 10 8 7 9 3 Parent(i) 1 return i/2 Left(i) 1 return 2i Right(i) 1 return 2i +1 1 2 3 4 5 6 7 8

More information

Lecture 3. Recurrences / Heapsort

Lecture 3. Recurrences / Heapsort Lecture 3. Recurrences / Heapsort T. H. Cormen, C. E. Leiserson and R. L. Rivest Introduction to Algorithms, 3rd Edition, MIT Press, 2009 Sungkyunkwan University Hyunseung Choo choo@skku.edu Copyright

More information

ADVANCED DATA STRUCTURES

ADVANCED DATA STRUCTURES ADVANCED DATA STRUCTURES Lecture 1 Introduction. Binary search trees. Efficiency issues Mircea Marin mircea.marin@e-uvt.ro Organizatorial items Lecturer and Teaching Assistant: Mircea Marin email: mircea.marin@e-uvt.ro

More information

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues.

Outline. Computer Science 331. Heap Shape. Binary Heaps. Heap Sort. Insertion Deletion. Mike Jacobson. HeapSort Priority Queues. Outline Computer Science 33 Heap Sort Mike Jacobson Department of Computer Science University of Calgary Lectures #5- Definition Representation 3 5 References Mike Jacobson (University of Calgary) Computer

More information

Data Structure and Algorithm, Spring 2017 Final Examination

Data Structure and Algorithm, Spring 2017 Final Examination Data Structure and Algorithm, Spring 2017 Final Examination Date: Tuesday, June 20, 2017 Time: 13:20-16:20pm (180 minutes) 138 points Non-Programming problems Problem 1. In each of the following question,

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms CSE 1, Winter 201 Design and Analysis of Algorithms Lecture 7: Bellman-Ford, SPs in DAGs, PQs Class URL: http://vlsicad.ucsd.edu/courses/cse1-w1/ Lec. Added after class Figure.: Single-Edge Extensions

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted

More information

Algorithms and Theory of Computation. Lecture 7: Priority Queue

Algorithms and Theory of Computation. Lecture 7: Priority Queue Algorithms and Theory of Computation Lecture 7: Priority Queue Xiaohui Bei MAS 714 September 5, 2017 Nanyang Technological University MAS 714 September 5, 2017 1 / 15 Priority Queues Priority Queues Store

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17 01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

More information

Lecture: Analysis of Algorithms (CS )

Lecture: Analysis of Algorithms (CS ) Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 1 Binary Search Trees Traversals, Querying, Insertion, and Deletion Sorting with BSTs 2 Example: Red-black Trees Height of a Red-black

More information

Sorting and Searching

Sorting and Searching Sorting and Searching Lecture 2: Priority Queues, Heaps, and Heapsort Lecture 2: Priority Queues, Heaps, and Heapsort Sorting and Searching 1 / 24 Priority Queue: Motivating Example 3 jobs have been submitted

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

CS102 Binary Search Trees

CS102 Binary Search Trees CS102 Binary Search Trees Prof Tejada 1 To speed up insertion, removal and search, modify the idea of a Binary Tree to create a Binary Search Tree (BST) Binary Search Trees Binary Search Trees have one

More information

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013

Advanced algorithms. binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap. Jiří Vyskočil, Radek Mařík 2013 binary heap, d-ary heap, binomial heap, amortized analysis, Fibonacci heap Jiří Vyskočil, Radek Mařík 2013 heap Heaps [haldy] a heap is a specialized data structure (usually tree-based) that satisfies

More information

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25

Multi-way Search Trees. (Multi-way Search Trees) Data Structures and Programming Spring / 25 Multi-way Search Trees (Multi-way Search Trees) Data Structures and Programming Spring 2017 1 / 25 Multi-way Search Trees Each internal node of a multi-way search tree T: has at least two children contains

More information

Algorithms. Deleting from Red-Black Trees B-Trees

Algorithms. Deleting from Red-Black Trees B-Trees Algorithms Deleting from Red-Black Trees B-Trees Recall the rules for BST deletion 1. If vertex to be deleted is a leaf, just delete it. 2. If vertex to be deleted has just one child, replace it with that

More information

(2,4) Trees. 2/22/2006 (2,4) Trees 1

(2,4) Trees. 2/22/2006 (2,4) Trees 1 (2,4) Trees 9 2 5 7 10 14 2/22/2006 (2,4) Trees 1 Outline and Reading Multi-way search tree ( 10.4.1) Definition Search (2,4) tree ( 10.4.2) Definition Search Insertion Deletion Comparison of dictionary

More information

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees

Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Dr. Chung- Wen Albert Tsao 1 Binary Search Trees Data structures that can support dynamic set operations. Search, Minimum, Maximum, Predecessor,

More information

Heaps, Heapsort, Priority Queues

Heaps, Heapsort, Priority Queues 9/8/208 Heaps, Heapsort, Priority Queues So Far Insertion Sort: O(n 2 ) worst case Linked List: O(n) search, some operations O(n 2 ) Heap: Data structure and associated algorithms, Not garbage collection

More information

Chapter 6 Heapsort 1

Chapter 6 Heapsort 1 Chapter 6 Heapsort 1 Introduce Heap About this lecture Shape Property and Heap Property Heap Operations Heapsort: Use Heap to Sort Fixing heap property for all nodes Use Array to represent Heap Introduce

More information

Binary Trees. Recursive definition. Is this a binary tree?

Binary Trees. Recursive definition. Is this a binary tree? Binary Search Trees Binary Trees Recursive definition 1. An empty tree is a binary tree 2. A node with two child subtrees is a binary tree 3. Only what you get from 1 by a finite number of applications

More information

A data structure and associated algorithms, NOT GARBAGE COLLECTION

A data structure and associated algorithms, NOT GARBAGE COLLECTION CS4 Lecture Notes /30/0 Heaps, Heapsort, Priority Queues Sorting problem so far: Heap: Insertion Sort: In Place, O( n ) worst case Merge Sort : Not in place, O( n lg n) worst case Quicksort : In place,

More information

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics

CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics CS2223: Algorithms Sorting Algorithms, Heap Sort, Linear-time sort, Median and Order Statistics 1 Sorting 1.1 Problem Statement You are given a sequence of n numbers < a 1, a 2,..., a n >. You need to

More information

Overview of Presentation. Heapsort. Heap Properties. What is Heap? Building a Heap. Two Basic Procedure on Heap

Overview of Presentation. Heapsort. Heap Properties. What is Heap? Building a Heap. Two Basic Procedure on Heap Heapsort Submitted by : Hardik Parikh(hjp0608) Soujanya Soni (sxs3298) Overview of Presentation Heap Definition. Adding a Node. Removing a Node. Array Implementation. Analysis What is Heap? A Heap is a

More information

Data Structures Week #6. Special Trees

Data Structures Week #6. Special Trees Data Structures Week #6 Special Trees Outline Adelson-Velskii-Landis (AVL) Trees Splay Trees B-Trees 21.Aralık.2010 Borahan Tümer, Ph.D. 2 AVL Trees 21.Aralık.2010 Borahan Tümer, Ph.D. 3 Motivation for

More information

Augmenting Data Structures

Augmenting Data Structures Augmenting Data Structures [Not in G &T Text. In CLRS chapter 14.] An AVL tree by itself is not very useful. To support more useful queries we need more structure. General Definition: An augmented data

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 11: Binary Search Trees MOUNA KACEM mouna@cs.wisc.edu Fall 2018 General Overview of Data Structures 2 Introduction to trees 3 Tree: Important non-linear data structure

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

Data Structures Week #6. Special Trees

Data Structures Week #6. Special Trees Data Structures Week #6 Special Trees Outline Adelson-Velskii-Landis (AVL) Trees Splay Trees B-Trees October 5, 2018 Borahan Tümer, Ph.D. 2 AVL Trees October 5, 2018 Borahan Tümer, Ph.D. 3 Motivation for

More information

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010

Uses for Trees About Trees Binary Trees. Trees. Seth Long. January 31, 2010 Uses for About Binary January 31, 2010 Uses for About Binary Uses for Uses for About Basic Idea Implementing Binary Example: Expression Binary Search Uses for Uses for About Binary Uses for Storage Binary

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS711008Z Algorithm Design and Analysis Lecture 7. Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / 108 Outline

More information

CS711008Z Algorithm Design and Analysis

CS711008Z Algorithm Design and Analysis CS700Z Algorithm Design and Analysis Lecture 7 Binary heap, binomial heap, and Fibonacci heap Dongbo Bu Institute of Computing Technology Chinese Academy of Sciences, Beijing, China 1 / Outline Introduction

More information

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are:

l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are: DDS-Heaps 1 Heaps - basics l Heaps very popular abstract data structure, where each object has a key value (the priority), and the operations are: l insert an object, find the object of minimum key (find

More information

Binary Heaps in Dynamic Arrays

Binary Heaps in Dynamic Arrays Yufei Tao ITEE University of Queensland We have already learned that the binary heap serves as an efficient implementation of a priority queue. Our previous discussion was based on pointers (for getting

More information

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn

Chapter 5 Data Structures Algorithm Theory WS 2016/17 Fabian Kuhn Chapter 5 Data Structures Algorithm Theory WS 06/ Fabian Kuhn Examples Dictionary: Operations: insert(key,value), delete(key), find(key) Implementations: Linked list: all operations take O(n) time (n:

More information

CSCI Trees. Mark Redekopp David Kempe

CSCI Trees. Mark Redekopp David Kempe CSCI 104 2-3 Trees Mark Redekopp David Kempe Trees & Maps/Sets C++ STL "maps" and "sets" use binary search trees internally to store their keys (and values) that can grow or contract as needed This allows

More information

Total Points: 60. Duration: 1hr

Total Points: 60. Duration: 1hr CS800 : Algorithms Fall 201 Nov 22, 201 Quiz 2 Practice Total Points: 0. Duration: 1hr 1. (,10) points Binary Heap. (a) The following is a sequence of elements presented to you (in order from left to right):

More information

W4231: Analysis of Algorithms

W4231: Analysis of Algorithms W4231: Analysis of Algorithms From Binomial Heaps to Fibonacci Heaps Fibonacci Heaps 10/7/1999 We first prove that in Binomial Heaps insert and find-min take amortized O(1) time, while still having insert,

More information

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1

(2,4) Trees Goodrich, Tamassia (2,4) Trees 1 (2,4) Trees 9 2 5 7 10 14 2004 Goodrich, Tamassia (2,4) Trees 1 Multi-Way Search Tree A multi-way search tree is an ordered tree such that Each internal node has at least two children and stores d -1 key-element

More information

Advanced Data Structures. Summary. January 9, Remember that binary search trees are binary trees such that:

Advanced Data Structures. Summary. January 9, Remember that binary search trees are binary trees such that: Advanced Data Structures Summary January 9, 2018 Binary search trees Remember that binary search trees are binary trees such that: Every node has satellite data and a unique key. The keys belong to a totally

More information

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible.

l So unlike the search trees, there are neither arbitrary find operations nor arbitrary delete operations possible. DDS-Heaps 1 Heaps - basics l Heaps an abstract structure where each object has a key value (the priority), and the operations are: insert an object, find the object of minimum key (find min), and delete

More information

Binary heaps (chapters ) Leftist heaps

Binary heaps (chapters ) Leftist heaps Binary heaps (chapters 20.3 20.5) Leftist heaps Binary heaps are arrays! A binary heap is really implemented using an array! 8 18 29 20 28 39 66 Possible because of completeness property 37 26 76 32 74

More information

Basic Data Structures (Version 7) Name:

Basic Data Structures (Version 7) Name: Prerequisite Concepts for Analysis of Algorithms Basic Data Structures (Version 7) Name: Email: Concept: mathematics notation 1. log 2 n is: Code: 21481 (A) o(log 10 n) (B) ω(log 10 n) (C) Θ(log 10 n)

More information

Data Structures Week #6. Special Trees

Data Structures Week #6. Special Trees Data Structures Week #6 Special Trees Outline Adelson-Velskii-Landis (AVL) Trees Splay Trees B-Trees October 5, 2015 Borahan Tümer, Ph.D. 2 AVL Trees October 5, 2015 Borahan Tümer, Ph.D. 3 Motivation for

More information

CMPS 2200 Fall 2017 Red-black trees Carola Wenk

CMPS 2200 Fall 2017 Red-black trees Carola Wenk CMPS 2200 Fall 2017 Red-black trees Carola Wenk Slides courtesy of Charles Leiserson with changes by Carola Wenk 9/13/17 CMPS 2200 Intro. to Algorithms 1 Dynamic Set A dynamic set, or dictionary, is a

More information

CS 310 Advanced Data Structures and Algorithms

CS 310 Advanced Data Structures and Algorithms CS 310 Advanced Data Structures and Algorithms Sorting June 13, 2017 Tong Wang UMass Boston CS 310 June 13, 2017 1 / 42 Sorting One of the most fundamental problems in CS Input: a series of elements with

More information

Algorithm Design (8) Graph Algorithms 1/2

Algorithm Design (8) Graph Algorithms 1/2 Graph Algorithm Design (8) Graph Algorithms / Graph:, : A finite set of vertices (or nodes) : A finite set of edges (or arcs or branches) each of which connect two vertices Takashi Chikayama School of

More information

1 Heaps. 1.1 What is a heap? 1.2 Representing a Heap. CS 124 Section #2 Heaps and Graphs 2/5/18

1 Heaps. 1.1 What is a heap? 1.2 Representing a Heap. CS 124 Section #2 Heaps and Graphs 2/5/18 CS 124 Section #2 Heaps and Graphs 2/5/18 1 Heaps Heaps are data structures that make it easy to find the element with the most extreme value in a collection of elements. They are also known a priority

More information

Lower Bound on Comparison-based Sorting

Lower Bound on Comparison-based Sorting Lower Bound on Comparison-based Sorting Different sorting algorithms may have different time complexity, how to know whether the running time of an algorithm is best possible? We know of several sorting

More information

Algorithms. AVL Tree

Algorithms. AVL Tree Algorithms AVL Tree Balanced binary tree The disadvantage of a binary search tree is that its height can be as large as N-1 This means that the time needed to perform insertion and deletion and many other

More information

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I

Department of Computer Applications. MCA 312: Design and Analysis of Algorithms. [Part I : Medium Answer Type Questions] UNIT I MCA 312: Design and Analysis of Algorithms [Part I : Medium Answer Type Questions] UNIT I 1) What is an Algorithm? What is the need to study Algorithms? 2) Define: a) Time Efficiency b) Space Efficiency

More information

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist.

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist. Sorting Popular algorithms: Selection sort* Insertion sort* Bubble sort* Quick sort* Comb-sort Shell-sort Heap sort* Merge sort* Counting-sort Radix-sort Bucket-sort Tim-sort Many algorithms for sorting

More information

INF2220: algorithms and data structures Series 1

INF2220: algorithms and data structures Series 1 Universitetet i Oslo Institutt for Informatikk A. Maus, R.K. Runde, I. Yu INF2220: algorithms and data structures Series 1 Topic Trees & estimation of running time (Exercises with hints for solution) Issued:

More information

Algorithms and Data Structures for Mathematicians

Algorithms and Data Structures for Mathematicians Algorithms and Data Structures for Mathematicians Lecture 3: Basic Data Structures Peter Kostolányi kostolanyi at fmph and so on Room M-258 12 October 2017 Dynamic Sets and Data Structures Many algorithms

More information

Data Structures and Algorithms for Engineers

Data Structures and Algorithms for Engineers 04-630 Data Structures and Algorithms for Engineers David Vernon Carnegie Mellon University Africa vernon@cmu.edu www.vernon.eu Data Structures and Algorithms for Engineers 1 Carnegie Mellon University

More information

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331

CSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331 CSE2331/5331 Topic 6: Binary Search Tree Data structure Operations Set Operations Maximum Extract-Max Insert Increase-key We can use priority queue (implemented by heap) Search Delete Successor Predecessor

More information

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed)

CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Name: Email address: CSE 373 Winter 2009: Midterm #1 (closed book, closed notes, NO calculators allowed) Instructions: Read the directions for each question carefully before answering. We may give partial

More information

O(n): printing a list of n items to the screen, looking at each item once.

O(n): printing a list of n items to the screen, looking at each item once. UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))

More information

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example.

Tree: non-recursive definition. Trees, Binary Search Trees, and Heaps. Tree: recursive definition. Tree: example. Trees, Binary Search Trees, and Heaps CS 5301 Fall 2013 Jill Seaman Tree: non-recursive definition Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every node (except

More information

Problem Set 5 Solutions

Problem Set 5 Solutions Introduction to Algorithms November 4, 2005 Massachusetts Institute of Technology 6.046J/18.410J Professors Erik D. Demaine and Charles E. Leiserson Handout 21 Problem Set 5 Solutions Problem 5-1. Skip

More information

Amortized Analysis. Andreas Klappenecker. [partially based on the slides of Prof. Welch]

Amortized Analysis. Andreas Klappenecker. [partially based on the slides of Prof. Welch] Amortized Analysis Andreas Klappenecker [partially based on the slides of Prof. Welch] 1 People who analyze algorithms have double happiness. First of all they experience the sheer beauty of elegant mathematical

More information

Next. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms.

Next. 1. Covered basics of a simple design technique (Divideand-conquer) 2. Next, more sorting algorithms. Next 1. Covered basics of a simple design technique (Divideand-conquer) Ch. 2 of the text. 2. Next, more sorting algorithms. Sorting Switch from design paradigms to applications. Sorting and order statistics

More information

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))

8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F)) DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]

More information

Binary Search Trees, etc.

Binary Search Trees, etc. Chapter 12 Binary Search Trees, etc. Binary Search trees are data structures that support a variety of dynamic set operations, e.g., Search, Minimum, Maximum, Predecessors, Successors, Insert, and Delete.

More information

Lecture 13: AVL Trees and Binary Heaps

Lecture 13: AVL Trees and Binary Heaps Data Structures Brett Bernstein Lecture 13: AVL Trees and Binary Heaps Review Exercises 1. ( ) Interview question: Given an array show how to shue it randomly so that any possible reordering is equally

More information

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT.

Week 10. Sorting. 1 Binary heaps. 2 Heapification. 3 Building a heap 4 HEAP-SORT. 5 Priority queues 6 QUICK-SORT. 7 Analysing QUICK-SORT. Week 10 1 2 3 4 5 6 Sorting 7 8 General remarks We return to sorting, considering and. Reading from CLRS for week 7 1 Chapter 6, Sections 6.1-6.5. 2 Chapter 7, Sections 7.1, 7.2. Discover the properties

More information

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree.

Module 4: Index Structures Lecture 13: Index structure. The Lecture Contains: Index structure. Binary search tree (BST) B-tree. B+-tree. The Lecture Contains: Index structure Binary search tree (BST) B-tree B+-tree Order file:///c /Documents%20and%20Settings/iitkrana1/My%20Documents/Google%20Talk%20Received%20Files/ist_data/lecture13/13_1.htm[6/14/2012

More information