25
Data Structures and Algorithms (CS210/ESO207/ESO211)  Lecture 28 Miscellaneous applica tion of binary trees - II 1

Lecture-28-CS210-2012.pptx

Embed Size (px)

Citation preview

PowerPoint Presentation

Data Structures and Algorithms(CS210/ESO207/ESO211) Lecture 28

Miscellaneous application of binary trees - II1Outline of the lecturePart 1:

A closer look at the binary tree data structure for Multi-Increment problem

Solution for Dynamic Range-minima Problem We shall go slowly on this topic so that all of you fully internalize the concept of this data structure. This topic manifests the true power of binary trees beyond dictionary problems and I would like all of you to realize and appreciate it

Part 2: (a sketch only)

Data structure for maintaining sets under two special operations

2Part 13A closer look at the binary tree data structure for Multi-IncrementAn insight into the hierarchy of intervals4An insight into the hierarchy of intervals 5An example: Locate the nodes defining interval [2,10] 6An example: Locate the nodes defining interval [6,8] 7Data structure for Multi-Increment8 How to do Multi-Increment(2,10,12) ? 94 14 9 17 23 21 29 91 37 25 8 33 2 67 11 44Initial sequence0 0 0 0 0 0 0 00 0 0 0 0 0 0 How to do Multi-Increment(2,10,12) ? 104 14 19 29 23 21 29 91 37 25 18 33 2 67 11 44Initial sequence0 0 0 0 12 0 0 00 12 0 0 0 0 0Proof of correctness11The solution of Multi-Increment Problem12Dynamic Range-minima

13Dynamic Range Minima Problem1433412Dynamic Range Minima Problem15Data structure for dynamic range minimaQuestion: What should be stored in the leaf nodes ?Answer: The initial sequence.Question: What should be stored in an internal node v ?Answer: minimum value stored in subtree(v).164 14 9 17 23 21 29 91 37 25 8 33 2 67 11 44Initial sequence49212925821128214242Data structure for dynamic range minima How to do Report-Min(2,10) ?

174 14 9 17 23 21 29 91 37 25 8 33 2 67 11 44Initial sequence24228214492129258211Data structure for dynamic range minima How to do Report-Min(2,10) ?

184 14 9 17 23 21 29 91 37 25 8 33 2 67 11 44Initial sequence24228214492129258211Data structure for dynamic range minima1901 23 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 4 14 9 17 23 21 29 91 37 25 8 33 2 67 11 44Initial sequence4921292582112821442220 There is an error in the above pseudocode. Try spotting it. (thanks to Karan Singh for pointing it out in the class)21 This is the correct pseudocode. 22Proof of correctnessLet T be the tree data structure for Dynamic Range-minima problem. Let u be any node in T.

Question: What can we say about value(u) after a series of operations ?

After every operation: value(u) is minimum among all values stores in the leaf nodes of subtree(u).

To prove the correctness of our datastructure/algorithm, you need to prove that the above mentioned assertion holds after each Update() operation. (Do it as a small exercise (4-5 sentences only)).

23Part 224A data structure for set for two special operationsSets under special operations25