9.7 Binomial Queues. This excerpt made available by permission of Robert Sedgewick, and of Pearson Education, Inc.

Size: px
Start display at page:

Download "9.7 Binomial Queues. This excerpt made available by permission of Robert Sedgewick, and of Pearson Education, Inc."

Transcription

1 CH lgorithms, 3rd dition, in Java, arts 1-4: Fundamentals, Data tructures, orting, and earching. obert edgewick, ddison-esley his excerpt made available by permission of obert edgewick, and of earson ducation, nc. (see rogram 5.19). Give the index heap tournament corresponding to the keys YQUO mplement the priority-queue D for index items (see rogram 9.11) using an index heap tournament (see xercise 9.46). 9.7 Binomial Queues one of the implementations that we have considered admit implementations of join, remove the maximum, andinsert that are all efficient in the worst case. Unordered linked lists have fast join and insert, but slow remove the maximum; ordered linked lists have fast remove the maximum, but slow join and insert; heaps have fast insert and remove the maximum, but slow join; and so forth. (ee able 9.1.) n applications where frequent or large join operations play an important role, we need to consider more advanced data structures. n this context, we mean by efficient that the operations should use no more than logarithmic time in the worst case. his restriction would seem to rule out array representations, because we can join two large arrays apparently only by moving all the elements in at least one of them. he unordered doubly linked-list representation of rogram 9.9 does the join in constant time, but requires that we walk through the whole list for remove the maximum. Use of a doubly linked ordered list (see xercise 9.40) gives a constant-timeremove the maximum, but requires linear time to merge lists for join. umerous data structures have been developed that can support efficient implementations of all the priority-queue operations. ost of them are based on direct linked representation of heap-ordered trees. wo links are needed for moving down the tree (either to both children in a binary tree or to the first child and next sibling in a binary tree representation of a general tree) and one link to the parent is needed for moving up the tree. Developing implementations of the heap-ordering operations that work for any (heap-ordered) tree shape with explicit nodes and links or other representation is generally straightforward. he difficulty lies in dynamic operations such as insert, remove, andjoin, which require us to modify the tree structure. Different data structures are based on different strategies for modifying the tree structure while still maintaining balance in the tree. he

2 OY QUU D HO algorithms use trees that are more flexible than are complete trees, but keep the trees sufficiently balanced to ensure a logarithmic time bound. he overhead of maintaining a triply linked structure ensuring that a particular implementation correctly maintains three pointers in all circumstances can be burdensome (see xercise 9.41). oreover, in many practical situations, it is difficult to demonstrate that efficient implementations of all the operations are required, so we might pause before taking on such an implementation. On the other hand, it is also difficult to demonstrate that efficient implementations are not required, and the investment to guarantee that all the priority-queue operations will be fast may be justified. egardless of such considerations, the next step from heaps to a data structure that allows for efficient implementation of join, insert, andremove the maximum is fascinating and worthy of study in its own right. ven with a linked representation for the trees, the heap condition and the condition that the heap-ordered binary tree be complete are too strong to allow efficient implementation of the join operation. Given two heap-ordered trees, how do we merge them together into just one tree? For example, if one of the trees has 1023 nodes and the other has 255 nodes, how can we merge them into a tree with 1278 nodes, without touching more than 10 or 20 nodes? t seems impossible to merge heap-ordered trees in general if the trees are to be heap ordered and complete, but various advanced data structures have been devised that weaken the heap-order and balance conditions to get the flexibility that we need to devise an efficient join. ext, we consider an ingenious solution to this problem, called the binomial queue, that was developed by Vuillemin in o begin, we note that the join operation is trivial for one particular type of tree with a relaxed heap-ordering restriction. Definition 9.4 binary tree comprising nodes with keys is said to be left heap ordered if the key in each node is larger than or equal to all the keys in that node s left subtree (if any). Definition 9.5 power-of-2 heap is a left-heap-ordered tree consisting of a root node with an empty right subtree and a complete left subtree. he tree corresponding to a power-of-2 heap by the left-child, right-sibling correspondence is called a binomial tree. O O G G Figure 9.15 binomial queue of size 13 binomial queue of size is a list of left-heap-ordered power-of- 2 heaps, one for each bit in the binary representation of. hus, a binomial queue of size 13 = consists of an 8-heap, a 4- heap, and a 1-heap. hown here are the left-heap-ordered powerof-2 heap representation (top) and the heap-ordered binomial-tree representation (bottom) of the same binomial queue.

3 CH X X O G O G rogram 9.13 Joining of two equal-sized power-of-2 heaps e need to change only a few links to combine two equal-sized powerof-2 heaps into one power-of-2 heap that is twice that size. his method, which we define as a private method in the implementation, is one key to the efficiency of the binomial queue algorithm. static ode pair(ode p, ode q) { if (p.item.less(q.item)) { p.r = q.l; q.l = p; return q; else { q.r = p.l; p.l = q; return p; O X G Figure 9.16 Joining of two equal-sized power-of-2 heaps. e join two power-of-two heaps (top) by putting the larger of the roots at the root, with that root s (left) subtree as the right subtree of the other original root. f the operands have 2 n nodes, the result has 2 n+1 nodes. f the operands are left-heap ordered, then so is the result, with the largest key at the root. he heap-ordered binomial-tree representation of the same operation is shown below the line. O X G Binomial trees and power-of-2 heaps are equivalent. e work with both representations because binomial trees are slightly easier to visualize, whereas the simple representation of power-of-2 heaps leads to simpler implementations. n particular, we depend upon the following facts, which are direct consequences of the definitions. he number of nodes in a power-of-2 heap is a power of 2. o node has a key larger than the key at the root. Binomial trees are heap-ordered. he trivial operation upon which binomial queue algorithms are based is that of joining two power-of-2 heaps that have an equal number of nodes. he result is a heap with twice as many nodes that is easy to create, as illustrated in Figure he root node with the larger key becomes the root of the result (with the other original root as the result root s left child), with its left subtree becoming the right subtree of the other root node. Given a linked representation for the trees, the join is a constant-time operation: e simply adjust two links at the top. n implementation is given in rogram his basic operation is at the heart of Vuillemin s general solution to the problem of implementing priority queues with no slow operations. Definition 9.6 binomial queue is a set of power-of-2 heaps, no two of the same size. he structure of a binomial queue is determined by that queue s number of nodes, by correspondence with the binary representation of integers.

4 OY QUU D HO binomial queue of elements has one power-of-2 heap for each 1 bit in the binary representation of. For example, a binomial queue of 13 nodes comprises an 8-heap, a 4-heap, and a 1-heap, as illustrated in Figure here are at most lg power-of-2 heaps in a binomial queue of size, all of height no greater than lg. n accordance with Definitions 9.5 and 9.6, we represent powerof-2 heaps (and handles to items) as links to nodes containing keys and two links (like the explicit tree representation of tournaments in Figure 5.10); and we represent binomial queues as arrays of power-of-2 heaps, by including the following private members in our implementation of rogram 9.8: private static class ode { tem item; ode l, r; ode(tem v) { item = v; l = null; r = null; ; private ode[] bq; he arrays are not large and the trees are not high; and this representation is sufficiently flexible to allow implementation of all the priority-queue operations in less than lg steps, as we shall now see. achlinkinthearraybq is a links to a power-of-2 heap: bq[i] is either null or a link to a 2 i -heap. s the queue grows and shrinks, the length of the array increases and decreases, but much less frequently: for example the array length increases by 1 only after the queue size doubles. t will be convenient to always have the last link null, so we begin with an array of size 1, a null link: Qfull() { bq = new ode[1]; bq[0] = null; thus adopting the convention that a queue is empty if and only if the array is of length 1. ow, let us consider the insert operation. he process of inserting a new item into a binomial queue mirrors precisely the process of incrementing a binary number. o increment a binary number, we move from right to left, changing 1s to 0s because of the carry associated with 1+1=10 2, until finding the rightmost 0, which we change to 1. n the analogous way, to add a new item to a binomial queue, we move from right to left, merging heaps corresponding to 1 bits with a

5 CH rogram 9.14 nsertion into a binomial queue o insert a node into a binomial queue, we first make the node into a 1- heap, identify it as a carry 1-heap, and then iterate the following process starting at i = 0. f the binomial queue has no 2 i -heap, we put the carry 2 i -heap into the queue. f the binomial queue has a 2 i -heap, we combine that with the new one (using the pair method from rogram 9.13) to make a 2 i+1 -heap, increment i, and iterate until finding an empty heap position in the binomial queue. hen we carry in to the null link at the end of the array, we call grow to increase the size of the array by 1 and put a null link in the new position (see text). Object insert(tem v) { ode t = new ode(v), c = t; for (int i = 0; i < bq.length+1; i++) { if (c == null) break; if (i == bq.length-1) bq = grow(bq); if (bq[i] == null) { bq[i] = c; break; c = pair(c, bq[i]); bq[i] = null; return t; Figure 9.17 nsertion of a new element into a binomial queue dding an element to a binomial queue of seven nodes is analogous to performing the binary addition = , with carries at each bit. he result is the binomial queue at the bottom, with an 8- heap and null 4-, 2-, and 1-heaps. carry heap, until finding the rightmost empty position to put the carry heap. pecifically, to insert a new item into a binomial queue, we make the new item into a 1-heap. hen, if is even (rightmost bit 0), we just put this 1-heap in the empty rightmost position of the binomial queue. f is odd (rightmost bit 1), we join the 1-heap corresponding to the new item with the 1-heap in the rightmost position of the binomial queue to make a carry 2-heap. f the position corresponding to 2 in the binomial queue is empty, we put the carry heap there; otherwise, we merge the carry 2-heap with the 2-heap from the binomial queue to make a carry 4-heap, and so forth, continuing until we get to an empty position in the binomial queue. his process is depicted in Figure 9.17; rogram 9.14 is an implementation. hen we add an element to a binomial queue with 2 k 1 items to make one with 2 k items, we carry into the null link at the end of the array, replacing it with a binomial tree of size 2 k (the rest of the

6 OY QUU D HO rogram 9.15 emoval of the maximum in a binomial queue e first scan the root nodes to find the maximum, and remove the power-of-2 heap containing the maximum from the binomial queue. e then remove the root node containing the maximum from its powerof-2 heap and temporarily build a binomial queue that contains the remaining constituent parts of the power-of-2 heap. Finally, we use the join operation to merge this binomial queue back into the original binomial queue. tem getmax() { int i, max; tem v = null; for (i = 0, max = -1; i < bq.length; i++) if (bq[i]!= null) if ((max == -1) v.less(bq[i].item)) { max = i; v = bq[max].item; ode[] temp = new ode[max+1]; temp[max] = null; ode x = bq[max].l; bq[max] = null; for (i = max-1; i >= 0; i--) { temp[i] = x; x = x.r; temp[i].r = null; bq = BQjoin(bq, temp); return v; links are all null). o adhere to our convention in this case, we need to add a null link at the end, which necessitates increasing the size of the array by 1. he method grow that rogram 9.14 invokes for this task is simple to implement (see xercise 9.62). Other binomial-queue operations are also best understood by analogy with binary arithmetic. s we shall see, implementing join corresponds to implementing addition for binary numbers. For the moment, assume that we have an (efficient) method for join that is organized to merge the priority-queue reference in its second operand with the priority-queue reference in its first operand (leaving the result in the first operand). Using this method, we could implement the insert operation with a call to the join method where one of the operands is a binomial queue of size 1 (see xercise 9.66). e can also implement the remove the maximum operation with one call to join. o find the maximum item in a binomial queue, we X O G O G Figure 9.18 emoval of the maximum in a power-of-2 heap aking away the root gives a forest of power-of-2 heaps, all left-heap ordered, with roots from the right spine of the tree. his operation leads to a way to remove the maximum element from a binomial queue: ake away the root of the power-of-2 heap that contains the largest element, then use the join operation to merge the resulting binomial queue with remaining power-of-2 heaps in the original binomial queue.

7 CH O G O G Figure 9.19 Joining of two binomial queues (no carry) hen two binomial queues to be joined do not have any powerof-2 heaps of the same size, the join operation is a simple merge. Doing this operation is analogous to adding two binary numbers without ever encountering 1+1(no carry). Here, a binomial queue of 10 nodes is merged with one of 5 nodes to make one of 15 nodes, corresponding to = scan the queue s power-of-2 heaps. ach of these heaps is left-heapordered, so it has its maximum element at the root. he largest of the items in the roots is the largest element in the binomial queue. Because there are no more than lg heaps in the binomial queue, the total time to find the maximum element is less than lg. o perform the remove the maximum operation, we note that removing the root of a left-ordered 2 k -heap leaves k left-ordered powerof-2 heaps a 2 k 1 -heap, a 2 k 2 -heap, and so forth which we can easily restructure into a binomial queue of size 2 k 1, as illustrated in Figure hen, we can use the join operation to combine this binomial queue with the rest of the original queue, to complete the remove the maximum operation. his implementation is given in rogram How do we join two binomial queues? First, we note that the operation is trivial if they do not contain two power-of-2 heaps of the same size, as illustrated in Figure 9.19: we simply merge the heaps from the two binomial queues to make one binomial queue. queue of size 10 (consisting of an 8-heap and a 2-heap) and a queue of size 5 (consisting of a 4-heap and a 1-heap) simply merge together to make a queue of size 15 (consisting of an 8-heap, a 4-heap, a 2-heap, and a 1-heap). he more general case follows by direct analogy with performing addition on two binary numbers, complete with carry, as illustrated in Figure For example, when we add a queue of size 7 (consisting of a 4-heap, a 2-heap, and a 1-heap) to a queue of size 3 (consisting of a 2-heap and a 1-heap), we get a queue of size 10 (consisting of an 8-heap and a 2-heap); to do the addition, we need to merge the 1- heaps and carry a 2-heap, then merge the 2-heaps and carry a 4-heap, then merge the 4-heaps to get an 8-heap result, in a manner precisely analogous to the binary addition = he example of Figure 9.19 is simpler than Figure 9.20 because it is analogous to = , with no carry. his direct analogy with binary arithmetic carries through to give us a natural implementation for the join operation (see rogram 9.16). For each bit, there are eight cases to consider, based on all the possible different values for the 3 bits involved (carry and two bits in the operands). he code is more complicated than that for plain addition, because we are dealing with distinguishable heaps, rather than with

8 OY QUU D HO indistinguishable bits, but each case is straightforward. For example, if all 3 bits are 1, we need to leave a heap in the result binomial queue, and to join the other two heaps for the carry into the next position. ndeed, this operation brings us full cycle on abstract data types: we (barely) resist the temptation to cast rogram 9.16 as a purely abstract binary addition procedure, with the binomial queue implementation nothing more than a client program using the more complicated bit addition procedure in rogram e do a join operation after reducing the size of the binomial queue by 1. f the next-to-last link in the result is null, then we can shrink the size of the array by 1, since the last link in the result will be null. he method shrink that rogram 9.16 invokes for this task is simple to implement (see xercise 9.62). roperty 9.7 ll the operations for the priority-queue D can be implemented with binomial queues such that O(lg ) steps are required for any operations performed on an -item queue. hese performance bounds are the goal of the design of the data structure. hey are direct consequences of the fact that the implementations all have only one or two loops that iterate through the roots of the trees in the binomial queue. nother option, which leads to a slightly simpler implementation, is to keep the number of tree in the queue constant, so the so the running time of all the methods is proportional to this number (the logarithm of the maximum size of the binomial queue) (see xercise 9.64). roperty 9.8 Construction of a binomial queue with insert operations on an initially empty queue requires O() comparisons in the worst case. For one-half the insertions (when the queue size is even and there is no 1-heap) no comparisons are required; for one-half the remaining insertions (when there is no 2-heap) only 1 comparison is required; when there is no 4-heap, only 2 comparisons are required; and so forth. hus, the total number of comparisons is less than 0 /2+1 /4+2 /8+...<. Binomial queues provide guaranteed fast performance, but data structures have been designed with even better theoretical performance Figure 9.20 Joining of two binomial queues dding a binomial queue of 3 nodes to one of 7 nodes gives one of 10 nodes through a process that mimics the binary addition = dding to gives an empty 1-heap in the result with a carry 2-heap containing and. hen adding the three 2-heaps leaves a 2-heap in the result with a carry 4-heap containing. his 4-heap is added to the other 4-heap, producing the binomial queue at the bottom. Few nodes are touched in the process.

9 CH rogram 9.16 Joining (merging) of two binomial queues his code mimics the operation of adding two binary numbers. roceeding from right to left with an initial carry bit of 0, we treat the eight possible cases (all possible values of the operands and carry bits) in a straightforward manner. For example, case 3 corresponds to the operand bits being both 1 and the carry 0. hen, the result is 0, but the carry is 1 (the result of adding the operand bits). e exchange the references if necessary to make a reference the queue with the larger array representation, and we increase or decrease the size of a s array for the result, if warranted. f there is a carry into the last (null) link in case 4, it invokes grow; if the next-to-last link is null after the operation is complete, it invokes shrink. ike pair, this method is a private method in the implementation, which is called by getmax and join. he implementation of the D method join(qfull p) is the invocation BQjoin(bq, p.bq). static int bit(ode x) { return x == null? 0 : 1; static int bits(ode C, ode B, ode ) { return 4*bit(C) + 2*bit(B) + 1*bit(); static ode[] BQjoin(ode[] a, ode[] b) { ode c = null; if (a.length < b.length) { ode[] t = a; a = b; b = t; for (int i = 0; i < b.length; i++) switch(bits(c, b[i], a[i])) { case 2: a[i] = b[i]; break; case 3: c = pair(a[i], b[i]); a[i] = null; break; case 4: if (i == a.length-1) a = grow(a); a[i] = c; c = null; break; case 5: c = pair(c, a[i]); a[i] = null; break; case 6: case 7: c = pair(c, b[i]); break; if (a[a.length-1] == null) a = shrink(a); return a;

10 OY QUU D HO characteristics, providing guaranteed constant-time performance for certain operations. his problem is an interesting and active area of data-structure design. On the other hand, the practical utility of many of these esoteric structures is dubious, and we need to be certain that performance bottlenecks exist that we can relieve only by reducing the running time of some priority-queue operation, before we delve into complex data-structure solutions. ndeed, for practical applications, we should prefer a trivial structure for debugging and for small queues; then, we should use heaps to speed up the operations unless fast join operations are required; finally, we should use binomial queues to guarantee logarithmic performance for all operations. ll things considered, however, a priority-queue package based on binomial queues is a valuable addition to a software library. xercises 9.54 Draw a binomial queue of size 29, using the binomial-tree representation rite a program to draw the binomial-tree representation of a binomial queue, given the size (just nodes connected by edges, no keys) Give the binomial queue that results when the keys YQU Oare inserted into an initially empty binomial queue Give the binomial queue that results when the keys Yare inserted into an initially empty binomial queue, and give the binomial queue that results when the keys QUO are inserted into an initially empty binomial queue. hen give the result of remove the maximum for each queue. Finally, give the result when the join operation is performed on the resulting queues Using the conventions of xercise 9.1 give the sequence of binomial queues produced when the operations O*****Y***QU***U* are performed on an initially empty binomial queue Using the conventions of xercise 9.2 give the sequence of binomial queues produced when the operations (((O*)+(**Y*))***)+(QU***U*) are performed on an initially empty binomial queue rove that a binomial tree with 2 n nodes has ( n i) nodes at level i for 0 i n. (his fact is the origin of the name binomial tree.) 9.61 Give an implementation for empty() that is appropriate for the binomial queue implementation given in the text.

11 CH 9.62 mplement the grow and shrink methods that increase by one and decrease by one, respectively, the size of a ode array leaving a null link in the last array position (shrink should throw an exception if that is not the case) Change the binomial queue implementation in the the text to represent the queues with Java Vector objects instead of arrays Develop a binomial-queue implementation that uses a fixed-size array of representation, so that grow and shrink are not needed, but the operations all take time proportional to the array size odify your solution such that roperty 9.7 holds, by maintaining a sentinel pointer to mark the point where the loops should terminate mplement insert for binomial queues by just using the join operation explicitly mplement change priority and remove for binomialqueues. ote: You will need to add a third link, which points up the tree, to the nodes dd an implementation of clone to the binomial queue implementations (rograms 9.13 through 9.16) in the text and test your implementation with your driver program from xercise mpirically compare binomial queues against heaps as the basis for sorting, as in rogram 9.6, for randomly ordered keys with = 1000, 10 4, 10 5,and Develop an in-place sorting method like heapsort, but based on binomial queues. Hint: ee xercise 9.38.

Design and Analysis of Algorithms 演算法設計與分析. Lecture 8 November 16, 2016 洪國寶

Design and Analysis of Algorithms 演算法設計與分析. Lecture 8 November 16, 2016 洪國寶 Design and Analysis of Algorithms 演算法設計與分析 Lecture 8 November 6, 206 洪國寶 Outline Review Amortized analysis Advanced data structures Binary heaps Binomial heaps Fibonacci heaps Data structures for disjoint

More information

3/7/13. Binomial Tree. Binomial Tree. Binomial Tree. Binomial Tree. Number of nodes with respect to k? N(B o ) = 1 N(B k ) = 2 N(B k-1 ) = 2 k

3/7/13. Binomial Tree. Binomial Tree. Binomial Tree. Binomial Tree. Number of nodes with respect to k? N(B o ) = 1 N(B k ) = 2 N(B k-1 ) = 2 k //1 Adapted from: Kevin Wayne B k B k B k : a binomial tree with the addition of a left child with another binomial tree Number of nodes with respect to k? N(B o ) = 1 N(B k ) = 2 N( ) = 2 k B 1 B 2 B

More information

Binary and Binomial Heaps. Disclaimer: these slides were adapted from the ones by Kevin Wayne

Binary and Binomial Heaps. Disclaimer: these slides were adapted from the ones by Kevin Wayne Binary and Binomial Heaps Disclaimer: these slides were adapted from the ones by Kevin Wayne Priority Queues Supports the following operations. Insert element x. Return min element. Return and delete minimum

More information

Data Structures. Binomial Heaps Fibonacci Heaps. Haim Kaplan & Uri Zwick December 2013

Data Structures. Binomial Heaps Fibonacci Heaps. Haim Kaplan & Uri Zwick December 2013 Data Structures Binomial Heaps Fibonacci Heaps Haim Kaplan & Uri Zwick December 13 1 Heaps / Priority queues Binary Heaps Binomial Heaps Lazy Binomial Heaps Fibonacci Heaps Insert Find-min Delete-min Decrease-key

More information

Design and Analysis of Algorithms 演算法設計與分析. Lecture 9 November 19, 2014 洪國寶

Design and Analysis of Algorithms 演算法設計與分析. Lecture 9 November 19, 2014 洪國寶 Design and Analysis of Algorithms 演算法設計與分析 Lecture 9 November 19, 2014 洪國寶 1 Outline Advanced data structures Binary heaps(review) Binomial heaps Fibonacci heaps Data structures for disjoint sets 2 Mergeable

More information

Priority Queues 9/10. Binary heaps Leftist heaps Binomial heaps Fibonacci heaps

Priority Queues 9/10. Binary heaps Leftist heaps Binomial heaps Fibonacci heaps Priority Queues 9/10 Binary heaps Leftist heaps Binomial heaps Fibonacci heaps Priority queues are important in, among other things, operating systems (process control in multitasking systems), search

More information

Design and Analysis of Algorithms. Lecture 9 November 20, 2013 洪國寶

Design and Analysis of Algorithms. Lecture 9 November 20, 2013 洪國寶 Design and Analysis of Algorithms 演算法設計與分析 Lecture 9 November 20, 2013 洪國寶 1 Outline Advanced data structures Binary heaps (review) Binomial heaps Fibonacci heaps Dt Data structures t for disjoint dijitsets

More information

Heaps

Heaps AdvancedAlgorithmics (4AP) Heaps Jaak Vilo 2009 Spring Jaak Vilo MTAT.03.190 Text Algorithms 1 Heaps http://en.wikipedia.org/wiki/category:heaps_(structure) Binary heap http://en.wikipedia.org/wiki/binary_heap

More information

1 Solutions to Tute09

1 Solutions to Tute09 s to Tute0 Questions 4. - 4. are straight forward. Q. 4.4 Show that in a binary tree of N nodes, there are N + NULL pointers. Every node has outgoing pointers. Therefore there are N pointers. Each node,

More information

Advanced Algorithmics (4AP) Heaps

Advanced Algorithmics (4AP) Heaps Advanced Algorithmics (4AP) Heaps Jaak Vilo 2009 Spring Jaak Vilo MTAT.03.190 Text Algorithms 1 Heaps http://en.wikipedia.org/wiki/category:heaps_(structure) Binary heap http://en.wikipedia.org/wiki/binary

More information

Heaps. Heap/Priority queue. Binomial heaps: Advanced Algorithmics (4AP) Heaps Binary heap. Binomial heap. Jaak Vilo 2009 Spring

Heaps. Heap/Priority queue. Binomial heaps: Advanced Algorithmics (4AP) Heaps Binary heap. Binomial heap. Jaak Vilo 2009 Spring .0.00 Heaps http://en.wikipedia.org/wiki/category:heaps_(structure) Advanced Algorithmics (4AP) Heaps Jaak Vilo 00 Spring Binary heap http://en.wikipedia.org/wiki/binary_heap Binomial heap http://en.wikipedia.org/wiki/binomial_heap

More information

Heaps. c P. Flener/IT Dept/Uppsala Univ. AD1, FP, PK II Heaps 1

Heaps. c P. Flener/IT Dept/Uppsala Univ. AD1, FP, PK II Heaps 1 Heaps (Version of 21 November 2005) A min-heap (resp. max-heap) is a data structure with fast extraction of the smallest (resp. largest) item (in O(lg n) time), as well as fast insertion (also in O(lg

More information

PRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley

PRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley PRIORITY QUEUES binary heaps d-ary heaps binomial heaps Fibonacci heaps Lecture slides by Kevin Wayne Copyright 2005 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated

More information

> asympt( ln( n! ), n ); n 360n n

> asympt( ln( n! ), n ); n 360n n 8.4 Heap Sort (heapsort) We will now look at our first (n ln(n)) algorithm: heap sort. It will use a data structure that we have already seen: a binary heap. 8.4.1 Strategy and Run-time Analysis Given

More information

Algorithms PRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. binary heaps d-ary heaps binomial heaps Fibonacci heaps

Algorithms PRIORITY QUEUES. binary heaps d-ary heaps binomial heaps Fibonacci heaps. binary heaps d-ary heaps binomial heaps Fibonacci heaps Priority queue data type Lecture slides by Kevin Wayne Copyright 05 Pearson-Addison Wesley http://www.cs.princeton.edu/~wayne/kleinberg-tardos PRIORITY QUEUES binary heaps d-ary heaps binomial heaps Fibonacci

More information

PARELLIZATION OF DIJKSTRA S ALGORITHM: COMPARISON OF VARIOUS PRIORITY QUEUES

PARELLIZATION OF DIJKSTRA S ALGORITHM: COMPARISON OF VARIOUS PRIORITY QUEUES PARELLIZATION OF DIJKSTRA S ALGORITHM: COMPARISON OF VARIOUS PRIORITY QUEUES WIKTOR JAKUBIUK, KESHAV PURANMALKA 1. Introduction Dijkstra s algorithm solves the single-sourced shorest path problem on a

More information

Outline for this Week

Outline for this Week Binomial Heaps Outline for this Week Binomial Heaps (Today) A simple, fexible, and versatile priority queue. Lazy Binomial Heaps (Today) A powerful building block for designing advanced data structures.

More information

Administration CSE 326: Data Structures

Administration CSE 326: Data Structures Administration CSE : Data Structures Binomial Queues Neva Cherniavsky Summer Released today: Project, phase B Due today: Homework Released today: Homework I have office hours tomorrow // Binomial Queues

More information

SET 1C Binary Trees. 2. (i) Define the height of a binary tree or subtree and also define a height balanced (AVL) tree. (2)

SET 1C Binary Trees. 2. (i) Define the height of a binary tree or subtree and also define a height balanced (AVL) tree. (2) SET 1C Binary Trees 1. Construct a binary tree whose preorder traversal is K L N M P R Q S T and inorder traversal is N L K P R M S Q T 2. (i) Define the height of a binary tree or subtree and also define

More information

Priority Queues. Fibonacci Heap

Priority Queues. Fibonacci Heap ibonacci Heap hans to Sartaj Sahni for the original version of the slides Operation mae-heap insert find-min delete-min union decrease-ey delete Priority Queues Lined List Binary Binomial Heaps ibonacci

More information

Outline for this Week

Outline for this Week Binomial Heaps Outline for this Week Binomial Heaps (Today) A simple, flexible, and versatile priority queue. Lazy Binomial Heaps (Today) A powerful building block for designing advanced data structures.

More information

Initializing A Max Heap. Initializing A Max Heap

Initializing A Max Heap. Initializing A Max Heap Initializing A Max Heap 3 4 5 6 7 8 70 8 input array = [-,,, 3, 4, 5, 6, 7, 8,, 0, ] Initializing A Max Heap 3 4 5 6 7 8 70 8 Start at rightmost array position that has a child. Index is n/. Initializing

More information

Ch 10 Trees. Introduction to Trees. Tree Representations. Binary Tree Nodes. Tree Traversals. Binary Search Trees

Ch 10 Trees. Introduction to Trees. Tree Representations. Binary Tree Nodes. Tree Traversals. Binary Search Trees Ch 10 Trees Introduction to Trees Tree Representations Binary Tree Nodes Tree Traversals Binary Search Trees 1 Binary Trees A binary tree is a finite set of elements called nodes. The set is either empty

More information

The potential function φ for the amortized analysis of an operation on Fibonacci heap at time (iteration) i is given by the following equation:

The potential function φ for the amortized analysis of an operation on Fibonacci heap at time (iteration) i is given by the following equation: Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600 127, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 01 Advanced Data Structures

More information

CSE 100: TREAPS AND RANDOMIZED SEARCH TREES

CSE 100: TREAPS AND RANDOMIZED SEARCH TREES CSE 100: TREAPS AND RANDOMIZED SEARCH TREES Midterm Review Practice Midterm covered during Sunday discussion Today Run time analysis of building the Huffman tree AVL rotations and treaps Huffman s algorithm

More information

On the Optimality of a Family of Binary Trees Techical Report TR

On the Optimality of a Family of Binary Trees Techical Report TR On the Optimality of a Family of Binary Trees Techical Report TR-011101-1 Dana Vrajitoru and William Knight Indiana University South Bend Department of Computer and Information Sciences Abstract In this

More information

CSCI 104 B-Trees (2-3, 2-3-4) and Red/Black Trees. Mark Redekopp David Kempe

CSCI 104 B-Trees (2-3, 2-3-4) and Red/Black Trees. Mark Redekopp David Kempe 1 CSCI 104 B-Trees (2-3, 2-3-4) and Red/Black Trees Mark Redekopp David Kempe 2 An example of B-Trees 2-3 TREES 3 Definition 2-3 Tree is a tree where Non-leaf nodes have 1 value & 2 children or 2 values

More information

Fundamental Algorithms - Surprise Test

Fundamental Algorithms - Surprise Test Technische Universität München Fakultät für Informatik Lehrstuhl für Effiziente Algorithmen Dmytro Chibisov Sandeep Sadanandan Winter Semester 007/08 Sheet Model Test January 16, 008 Fundamental Algorithms

More information

COMP Analysis of Algorithms & Data Structures

COMP Analysis of Algorithms & Data Structures COMP 3170 - Analysis of Algorithms & Data Structures Shahin Kamali Binomial Heaps CLRS 6.1, 6.2, 6.3 University of Manitoba Priority queues A priority queue is an abstract data type formed by a set S of

More information

CSE 21 Winter 2016 Homework 6 Due: Wednesday, May 11, 2016 at 11:59pm. Instructions

CSE 21 Winter 2016 Homework 6 Due: Wednesday, May 11, 2016 at 11:59pm. Instructions CSE 1 Winter 016 Homework 6 Due: Wednesday, May 11, 016 at 11:59pm Instructions Homework should be done in groups of one to three people. You are free to change group members at any time throughout the

More information

Stanford University, CS 106X Homework Assignment 5: Priority Queue Binomial Heap Optional Extension

Stanford University, CS 106X Homework Assignment 5: Priority Queue Binomial Heap Optional Extension Stanford University, CS 106X Homework Assignment 5: Priority Queue Binomial Heap Optional Extension Extension description by Jerry Cain. This document describes an optional extension to the assignment.

More information

Meld(Q 1,Q 2 ) merge two sets

Meld(Q 1,Q 2 ) merge two sets Priority Queues MakeQueue Insert(Q,k,p) Delete(Q,k) DeleteMin(Q) Meld(Q 1,Q 2 ) Empty(Q) Size(Q) FindMin(Q) create new empty queue insert key k with priority p delete key k (given a pointer) delete key

More information

1.6 Heap ordered trees

1.6 Heap ordered trees 1.6 Heap ordered trees A heap ordered tree is a tree satisfying the following condition. The key of a node is not greater than that of each child if any In a heap ordered tree, we can not implement find

More information

Fibonacci Heaps CLRS: Chapter 20 Last Revision: 21/09/04

Fibonacci Heaps CLRS: Chapter 20 Last Revision: 21/09/04 Fibonacci Heaps CLRS: Chapter 20 Last Revision: 21/09/04 1 Binary heap Binomial heap Fibonacci heap Procedure (worst-case) (worst-case) (amortized) Make-Heap Θ(1) Θ(1) Θ(1) Insert Θ(lg n) O(lg n) Θ(1)

More information

COSC160: Data Structures Binary Trees. Jeremy Bolton, PhD Assistant Teaching Professor

COSC160: Data Structures Binary Trees. Jeremy Bolton, PhD Assistant Teaching Professor COSC160: Data Structures Binary Trees Jeremy Bolton, PhD Assistant Teaching Professor Outline I. Binary Trees I. Implementations I. Memory Management II. Binary Search Tree I. Operations Binary Trees A

More information

1 Binomial Tree. Structural Properties:

1 Binomial Tree. Structural Properties: Indian Institute of Information Technology Design and Manufacturing, Kancheepuram Chennai 600, India An Autonomous Institute under MHRD, Govt of India http://www.iiitdm.ac.in COM 0 Advanced Data Structures

More information

2 all subsequent nodes. 252 all subsequent nodes. 401 all subsequent nodes. 398 all subsequent nodes. 330 all subsequent nodes

2 all subsequent nodes. 252 all subsequent nodes. 401 all subsequent nodes. 398 all subsequent nodes. 330 all subsequent nodes ¼ À ÈÌ Ê ½¾ ÈÊÇ Ä ÅË ½µ ½¾º¾¹½ ¾µ ½¾º¾¹ µ ½¾º¾¹ µ ½¾º¾¹ µ ½¾º ¹ µ ½¾º ¹ µ ½¾º ¹¾ µ ½¾º ¹ µ ½¾¹¾ ½¼µ ½¾¹ ½ (1) CLR 12.2-1 Based on the structure of the binary tree, and the procedure of Tree-Search, any

More information

Introduction to Greedy Algorithms: Huffman Codes

Introduction to Greedy Algorithms: Huffman Codes Introduction to Greedy Algorithms: Huffman Codes Yufei Tao ITEE University of Queensland In computer science, one interesting method to design algorithms is to go greedy, namely, keep doing the thing that

More information

Priority queue. Advanced Algorithmics (6EAP) Binary heap. Heap/Priority queue. Binomial heaps: Merge two heaps.

Priority queue. Advanced Algorithmics (6EAP) Binary heap. Heap/Priority queue. Binomial heaps: Merge two heaps. Priority queue Advanced Algorithmics (EAP) MTAT.03.38 Heaps Jaak Vilo 0 Spring Insert Q, x Retrieve x from Q s.t. x.value is min (or max) Sorted linked list: O(n) to insert x into right place O() access-

More information

Chapter 16. Binary Search Trees (BSTs)

Chapter 16. Binary Search Trees (BSTs) Chapter 16 Binary Search Trees (BSTs) Search trees are tree-based data structures that can be used to store and search for items that satisfy a total order. There are many types of search trees designed

More information

Supporting Information

Supporting Information Supporting Information Novikoff et al. 0.073/pnas.0986309 SI Text The Recap Method. In The Recap Method in the paper, we described a schedule in terms of a depth-first traversal of a full binary tree,

More information

AVL Trees. The height of the left subtree can differ from the height of the right subtree by at most 1.

AVL Trees. The height of the left subtree can differ from the height of the right subtree by at most 1. AVL Trees In order to have a worst case running time for insert and delete operations to be O(log n), we must make it impossible for there to be a very long path in the binary search tree. The first balanced

More information

CSCE 750, Fall 2009 Quizzes with Answers

CSCE 750, Fall 2009 Quizzes with Answers CSCE 750, Fall 009 Quizzes with Answers Stephen A. Fenner September 4, 011 1. Give an exact closed form for Simplify your answer as much as possible. k 3 k+1. We reduce the expression to a form we ve already

More information

4/8/13. Part 6. Trees (2) Outline. Balanced Search Trees. 2-3 Trees Trees Red-Black Trees AVL Trees. to maximum n. Tree A. Tree B.

4/8/13. Part 6. Trees (2) Outline. Balanced Search Trees. 2-3 Trees Trees Red-Black Trees AVL Trees. to maximum n. Tree A. Tree B. art 6. Trees (2) C 200 Algorithms and Data tructures 1 Outline 2-3 Trees 2-3-4 Trees Red-Black Trees AV Trees 2 Balanced earch Trees Tree A Tree B to maximum n Tree D 3 1 Balanced earch Trees A search

More information

Successor. CS 361, Lecture 19. Tree-Successor. Outline

Successor. CS 361, Lecture 19. Tree-Successor. Outline Successor CS 361, Lecture 19 Jared Saia University of New Mexico The successor of a node x is the node that comes after x in the sorted order determined by an in-order tree walk. If all keys are distinct,

More information

Heap Building Bounds

Heap Building Bounds Heap Building Bounds Zhentao Li 1 and Bruce A. Reed 2 1 School of Computer Science, McGill University zhentao.li@mail.mcgill.ca 2 School of Computer Science, McGill University breed@cs.mcgill.ca Abstract.

More information

Binary Tree Applications

Binary Tree Applications Binary Tree Applications Lecture 32 Section 19.2 Robb T. Koether Hampden-Sydney College Wed, Apr 17, 2013 Robb T. Koether (Hampden-Sydney College) Binary Tree Applications Wed, Apr 17, 2013 1 / 46 1 Expression

More information

CS4311 Design and Analysis of Algorithms. Lecture 14: Amortized Analysis I

CS4311 Design and Analysis of Algorithms. Lecture 14: Amortized Analysis I CS43 Design and Analysis of Algorithms Lecture 4: Amortized Analysis I About this lecture Given a data structure, amortized analysis studies in a sequence of operations, the average time to perform an

More information

Splay Trees. Splay Trees - 1

Splay Trees. Splay Trees - 1 Splay Trees In balanced tree schemes, explicit rules are followed to ensure balance. In splay trees, there are no such rules. Search, insert, and delete operations are like in binary search trees, except

More information

Lecture 4: Divide and Conquer

Lecture 4: Divide and Conquer Lecture 4: Divide and Conquer Divide and Conquer Merge sort is an example of a divide-and-conquer algorithm Recall the three steps (at each level to solve a divideand-conquer problem recursively Divide

More information

Basic Data Structures. Figure 8.1 Lists, stacks, and queues. Terminology for Stacks. Terminology for Lists. Chapter 8: Data Abstractions

Basic Data Structures. Figure 8.1 Lists, stacks, and queues. Terminology for Stacks. Terminology for Lists. Chapter 8: Data Abstractions Chapter 8: Data Abstractions Computer Science: An Overview Tenth Edition by J. Glenn Brookshear Chapter 8: Data Abstractions 8.1 Data Structure Fundamentals 8.2 Implementing Data Structures 8.3 A Short

More information

Homework #4. CMSC351 - Spring 2013 PRINT Name : Due: Thu Apr 16 th at the start of class

Homework #4. CMSC351 - Spring 2013 PRINT Name : Due: Thu Apr 16 th at the start of class Homework #4 CMSC351 - Spring 2013 PRINT Name : Due: Thu Apr 16 th at the start of class o Grades depend on neatness and clarity. o Write your answers with enough detail about your approach and concepts

More information

Design and Analysis of Algorithms

Design and Analysis of Algorithms Design and Analysis of Algorithms Instructor: Sharma Thankachan Lecture 9: Binomial Heap Slides modified from Dr. Hon, with permission 1 About this lecture Binary heap supports various operations quickly:

More information

Data Structures, Algorithms, & Applications in C++ ( Chapter 9 )

Data Structures, Algorithms, & Applications in C++ ( Chapter 9 ) ) Priority Queues Two kinds of priority queues: Min priority queue. Max priority queue. Min Priority Queue Collection of elements. Each element has a priority or key. Supports following operations: isempty

More information

Unit 6: Amortized Analysis

Unit 6: Amortized Analysis : Amortized Analysis Course contents: Aggregate method Accounting method Potential method Reading: Chapter 17 Y.-W. Chang 1 Amortized Analysis Why Amortized Analysis? Find a tight bound of a sequence of

More information

Lecture 5: Tuesday, January 27, Peterson s Algorithm satisfies the No Starvation property (Theorem 1)

Lecture 5: Tuesday, January 27, Peterson s Algorithm satisfies the No Starvation property (Theorem 1) Com S 611 Spring Semester 2015 Advanced Topics on Distributed and Concurrent Algorithms Lecture 5: Tuesday, January 27, 2015 Instructor: Soma Chaudhuri Scribe: Nik Kinkel 1 Introduction This lecture covers

More information

Chapter 7 Sorting (Part II)

Chapter 7 Sorting (Part II) Data Structure t Chapter 7 Sorting (Part II) Angela Chih-Wei i Tang Department of Communication Engineering National Central University Jhongli, Taiwan 2010 Spring Outline Heap Max/min heap Insertion &

More information

Sublinear Time Algorithms Oct 19, Lecture 1

Sublinear Time Algorithms Oct 19, Lecture 1 0368.416701 Sublinear Time Algorithms Oct 19, 2009 Lecturer: Ronitt Rubinfeld Lecture 1 Scribe: Daniel Shahaf 1 Sublinear-time algorithms: motivation Twenty years ago, there was practically no investigation

More information

Structural Induction

Structural Induction Structural Induction Jason Filippou CMSC250 @ UMCP 07-05-2016 Jason Filippou (CMSC250 @ UMCP) Structural Induction 07-05-2016 1 / 26 Outline 1 Recursively defined structures 2 Proofs Binary Trees Jason

More information

Fibonacci Heaps Y Y o o u u c c an an s s u u b b m miitt P P ro ro b blle e m m S S et et 3 3 iin n t t h h e e b b o o x x u u p p fro fro n n tt..

Fibonacci Heaps Y Y o o u u c c an an s s u u b b m miitt P P ro ro b blle e m m S S et et 3 3 iin n t t h h e e b b o o x x u u p p fro fro n n tt.. Fibonacci Heaps You You can can submit submit Problem Problem Set Set 3 in in the the box box up up front. front. Outline for Today Review from Last Time Quick refresher on binomial heaps and lazy binomial

More information

Finding Equilibria in Games of No Chance

Finding Equilibria in Games of No Chance Finding Equilibria in Games of No Chance Kristoffer Arnsfelt Hansen, Peter Bro Miltersen, and Troels Bjerre Sørensen Department of Computer Science, University of Aarhus, Denmark {arnsfelt,bromille,trold}@daimi.au.dk

More information

******************************* The multi-period binomial model generalizes the single-period binomial model we considered in Section 2.

******************************* The multi-period binomial model generalizes the single-period binomial model we considered in Section 2. Derivative Securities Multiperiod Binomial Trees. We turn to the valuation of derivative securities in a time-dependent setting. We focus for now on multi-period binomial models, i.e. binomial trees. This

More information

THE TRAVELING SALESMAN PROBLEM FOR MOVING POINTS ON A LINE

THE TRAVELING SALESMAN PROBLEM FOR MOVING POINTS ON A LINE THE TRAVELING SALESMAN PROBLEM FOR MOVING POINTS ON A LINE GÜNTER ROTE Abstract. A salesperson wants to visit each of n objects that move on a line at given constant speeds in the shortest possible time,

More information

Outline for Today. Quick refresher on binomial heaps and lazy binomial heaps. An important operation in many graph algorithms.

Outline for Today. Quick refresher on binomial heaps and lazy binomial heaps. An important operation in many graph algorithms. Fibonacci Heaps Outline for Today Review from Last Time Quick refresher on binomial heaps and lazy binomial heaps. The Need for decrease-key An important operation in many graph algorithms. Fibonacci Heaps

More information

NOTES ON FIBONACCI TREES AND THEIR OPTIMALITY* YASUICHI HORIBE INTRODUCTION 1. FIBONACCI TREES

NOTES ON FIBONACCI TREES AND THEIR OPTIMALITY* YASUICHI HORIBE INTRODUCTION 1. FIBONACCI TREES 0#0# NOTES ON FIBONACCI TREES AND THEIR OPTIMALITY* YASUICHI HORIBE Shizuoka University, Hamamatsu, 432, Japan (Submitted February 1982) INTRODUCTION Continuing a previous paper [3], some new observations

More information

Optimal Satisficing Tree Searches

Optimal Satisficing Tree Searches Optimal Satisficing Tree Searches Dan Geiger and Jeffrey A. Barnett Northrop Research and Technology Center One Research Park Palos Verdes, CA 90274 Abstract We provide an algorithm that finds optimal

More information

Recall: Data Flow Analysis. Data Flow Analysis Recall: Data Flow Equations. Forward Data Flow, Again

Recall: Data Flow Analysis. Data Flow Analysis Recall: Data Flow Equations. Forward Data Flow, Again Data Flow Analysis 15-745 3/24/09 Recall: Data Flow Analysis A framework for proving facts about program Reasons about lots of little facts Little or no interaction between facts Works best on properties

More information

UNIT 2. Greedy Method GENERAL METHOD

UNIT 2. Greedy Method GENERAL METHOD UNIT 2 GENERAL METHOD Greedy Method Greedy is the most straight forward design technique. Most of the problems have n inputs and require us to obtain a subset that satisfies some constraints. Any subset

More information

Maximum Contiguous Subsequences

Maximum Contiguous Subsequences Chapter 8 Maximum Contiguous Subsequences In this chapter, we consider a well-know problem and apply the algorithm-design techniques that we have learned thus far to this problem. While applying these

More information

DESCENDANTS IN HEAP ORDERED TREES OR A TRIUMPH OF COMPUTER ALGEBRA

DESCENDANTS IN HEAP ORDERED TREES OR A TRIUMPH OF COMPUTER ALGEBRA DESCENDANTS IN HEAP ORDERED TREES OR A TRIUMPH OF COMPUTER ALGEBRA Helmut Prodinger Institut für Algebra und Diskrete Mathematik Technical University of Vienna Wiedner Hauptstrasse 8 0 A-00 Vienna, Austria

More information

CSE 417 Dynamic Programming (pt 2) Look at the Last Element

CSE 417 Dynamic Programming (pt 2) Look at the Last Element CSE 417 Dynamic Programming (pt 2) Look at the Last Element Reminders > HW4 is due on Friday start early! if you run into problems loading data (date parsing), try running java with Duser.country=US Duser.language=en

More information

Principles of Program Analysis: Algorithms

Principles of Program Analysis: Algorithms Principles of Program Analysis: Algorithms Transparencies based on Chapter 6 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis. Springer Verlag 2005. c

More information

0/1 knapsack problem knapsack problem

0/1 knapsack problem knapsack problem 1 (1) 0/1 knapsack problem. A thief robbing a safe finds it filled with N types of items of varying size and value, but has only a small knapsack of capacity M to use to carry the goods. More precisely,

More information

3: Balance Equations

3: Balance Equations 3.1 Balance Equations Accounts with Constant Interest Rates 15 3: Balance Equations Investments typically consist of giving up something today in the hope of greater benefits in the future, resulting in

More information

ELEMENTS OF MATRIX MATHEMATICS

ELEMENTS OF MATRIX MATHEMATICS QRMC07 9/7/0 4:45 PM Page 5 CHAPTER SEVEN ELEMENTS OF MATRIX MATHEMATICS 7. AN INTRODUCTION TO MATRICES Investors frequently encounter situations involving numerous potential outcomes, many discrete periods

More information

Probability. An intro for calculus students P= Figure 1: A normal integral

Probability. An intro for calculus students P= Figure 1: A normal integral Probability An intro for calculus students.8.6.4.2 P=.87 2 3 4 Figure : A normal integral Suppose we flip a coin 2 times; what is the probability that we get more than 2 heads? Suppose we roll a six-sided

More information

Lecture l(x) 1. (1) x X

Lecture l(x) 1. (1) x X Lecture 14 Agenda for the lecture Kraft s inequality Shannon codes The relation H(X) L u (X) = L p (X) H(X) + 1 14.1 Kraft s inequality While the definition of prefix-free codes is intuitively clear, we

More information

Chapter 5: Algorithms

Chapter 5: Algorithms Chapter 5: Algorithms Computer Science: An Overview Tenth Edition by J. Glenn Brookshear Presentation files modified by Farn Wang Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

More information

UNIT VI TREES. Marks - 14

UNIT VI TREES. Marks - 14 UNIT VI TREES Marks - 14 SYLLABUS 6.1 Non-linear data structures 6.2 Binary trees : Complete Binary Tree, Basic Terms: level number, degree, in-degree and out-degree, leaf node, directed edge, path, depth,

More information

About this lecture. Three Methods for the Same Purpose (1) Aggregate Method (2) Accounting Method (3) Potential Method.

About this lecture. Three Methods for the Same Purpose (1) Aggregate Method (2) Accounting Method (3) Potential Method. About this lecture Given a data structure, amortized analysis studies in a sequence of operations, the average time to perform an operation Introduce amortized cost of an operation Three Methods for the

More information

On the Optimality of a Family of Binary Trees

On the Optimality of a Family of Binary Trees On the Optimality of a Family of Binary Trees Dana Vrajitoru Computer and Information Sciences Department Indiana University South Bend South Bend, IN 46645 Email: danav@cs.iusb.edu William Knight Computer

More information

Yao s Minimax Principle

Yao s Minimax Principle Complexity of algorithms The complexity of an algorithm is usually measured with respect to the size of the input, where size may for example refer to the length of a binary word describing the input,

More information

Essays on Some Combinatorial Optimization Problems with Interval Data

Essays on Some Combinatorial Optimization Problems with Interval Data Essays on Some Combinatorial Optimization Problems with Interval Data a thesis submitted to the department of industrial engineering and the institute of engineering and sciences of bilkent university

More information

CMPSCI 311: Introduction to Algorithms Second Midterm Practice Exam SOLUTIONS

CMPSCI 311: Introduction to Algorithms Second Midterm Practice Exam SOLUTIONS CMPSCI 311: Introduction to Algorithms Second Midterm Practice Exam SOLUTIONS November 17, 2016. Name: ID: Instructions: Answer the questions directly on the exam pages. Show all your work for each question.

More information

Real Estate Private Equity Case Study 3 Opportunistic Pre-Sold Apartment Development: Waterfall Returns Schedule, Part 1: Tier 1 IRRs and Cash Flows

Real Estate Private Equity Case Study 3 Opportunistic Pre-Sold Apartment Development: Waterfall Returns Schedule, Part 1: Tier 1 IRRs and Cash Flows Real Estate Private Equity Case Study 3 Opportunistic Pre-Sold Apartment Development: Waterfall Returns Schedule, Part 1: Tier 1 IRRs and Cash Flows Welcome to the next lesson in this Real Estate Private

More information

Solution Week 60 (11/3/03) Cereal box prizes

Solution Week 60 (11/3/03) Cereal box prizes Solution Wee 60 /3/03 Cereal box prizes First Solution: Assume that you have collected c of the colors, and let B c be the number of boxes it taes to get the next color. The average value of B c, which

More information

Empirical and Average Case Analysis

Empirical and Average Case Analysis Empirical and Average Case Analysis l We have discussed theoretical analysis of algorithms in a number of ways Worst case big O complexities Recurrence relations l What we often want to know is what will

More information

CS473-Algorithms I. Lecture 12. Amortized Analysis. Cevdet Aykanat - Bilkent University Computer Engineering Department

CS473-Algorithms I. Lecture 12. Amortized Analysis. Cevdet Aykanat - Bilkent University Computer Engineering Department CS473-Algorithms I Lecture 12 Amortized Analysis 1 Amortized Analysis Key point: The time required to perform a sequence of data structure operations is averaged over all operations performed Amortized

More information

COMP251: Amortized Analysis

COMP251: Amortized Analysis COMP251: Amortized Analysis Jérôme Waldispühl School of Computer Science McGill University Based on (Cormen et al., 2009) T n = 2 % T n 5 + n( What is the height of the recursion tree? log ( n log, n log

More information

Martingale Pricing Theory in Discrete-Time and Discrete-Space Models

Martingale Pricing Theory in Discrete-Time and Discrete-Space Models IEOR E4707: Foundations of Financial Engineering c 206 by Martin Haugh Martingale Pricing Theory in Discrete-Time and Discrete-Space Models These notes develop the theory of martingale pricing in a discrete-time,

More information

Prepayment Vector. The PSA tries to capture how prepayments vary with age. But it should be viewed as a market convention rather than a model.

Prepayment Vector. The PSA tries to capture how prepayments vary with age. But it should be viewed as a market convention rather than a model. Prepayment Vector The PSA tries to capture how prepayments vary with age. But it should be viewed as a market convention rather than a model. A vector of PSAs generated by a prepayment model should be

More information

SPAN for ICE SPAN Array File Formats for Energy Products

SPAN for ICE SPAN Array File Formats for Energy Products SPAN for ICE SPAN Array File Formats for Energy Products Version 2.5 7 March 2012 1 Introduction... 3 2 General... 4 3 Processing the Enhanced Record Types in SPAN for ICE... 8 4 Record Formats - CSV...

More information

An Experimental Study of the Behaviour of the Proxel-Based Simulation Algorithm

An Experimental Study of the Behaviour of the Proxel-Based Simulation Algorithm An Experimental Study of the Behaviour of the Proxel-Based Simulation Algorithm Sanja Lazarova-Molnar, Graham Horton Otto-von-Guericke-Universität Magdeburg Abstract The paradigm of the proxel ("probability

More information

Enhanced Shell Sorting Algorithm

Enhanced Shell Sorting Algorithm Enhanced ing Algorithm Basit Shahzad, and Muhammad Tanvir Afzal Abstract Many algorithms are available for sorting the unordered elements. Most important of them are Bubble sort, Heap sort, Insertion sort

More information

Chapter 15: Dynamic Programming

Chapter 15: Dynamic Programming Chapter 15: Dynamic Programming Dynamic programming is a general approach to making a sequence of interrelated decisions in an optimum way. While we can describe the general characteristics, the details

More information

Issues. Senate (Total = 100) Senate Group 1 Y Y N N Y 32 Senate Group 2 Y Y D N D 16 Senate Group 3 N N Y Y Y 30 Senate Group 4 D Y N D Y 22

Issues. Senate (Total = 100) Senate Group 1 Y Y N N Y 32 Senate Group 2 Y Y D N D 16 Senate Group 3 N N Y Y Y 30 Senate Group 4 D Y N D Y 22 1. Every year, the United States Congress must approve a budget for the country. In order to be approved, the budget must get a majority of the votes in the Senate, a majority of votes in the House, and

More information

Lecture 7. Analysis of algorithms: Amortized Analysis. January Lecture 7

Lecture 7. Analysis of algorithms: Amortized Analysis. January Lecture 7 Analysis of algorithms: Amortized Analysis January 2014 What is amortized analysis? Amortized analysis: set of techniques (Aggregate method, Accounting method, Potential method) for proving upper (worst-case)

More information

BITTIGER #11. Oct

BITTIGER #11. Oct BITTIGER #11 Oct 22 2016 PROBLEM LIST A. Five in a Row brute force, implementation B. Building Heap data structures, divide and conquer C. Guess Number with Lower or Higher Hints dynamic programming, mathematics

More information

A relation on 132-avoiding permutation patterns

A relation on 132-avoiding permutation patterns Discrete Mathematics and Theoretical Computer Science DMTCS vol. VOL, 205, 285 302 A relation on 32-avoiding permutation patterns Natalie Aisbett School of Mathematics and Statistics, University of Sydney,

More information

While the story has been different in each case, fundamentally, we ve maintained:

While the story has been different in each case, fundamentally, we ve maintained: Econ 805 Advanced Micro Theory I Dan Quint Fall 2009 Lecture 22 November 20 2008 What the Hatfield and Milgrom paper really served to emphasize: everything we ve done so far in matching has really, fundamentally,

More information