620 likes | 640 Views
Data Structures. Amazing but less known world of. Surender Baswana Visiting Professor till 31 st May 2020 Heinz Nixdorf Institute & Department of Computer Science (Algorithms and Complexity Group) sbaswana@campus.uni-paderborn.de sbaswana@gmail.com. Data Structures.
E N D
Data Structures Amazing but less known world of SurenderBaswana Visiting Professor till 31st May 2020 Heinz Nixdorf Institute & Department of Computer Science(Algorithms and Complexity Group) sbaswana@campus.uni-paderborn.de sbaswana@gmail.com
Data Structures Aim: How to organize data compactly so that each operation is executed efficiently.
Data Structures Phone number of Mr. XYZ ? Lexicographically sorted Binary search
Data structures in courses/books (log ) () Fibonaacci heap Maximum Flow Algorithm
> > > Library for Efficient Data Structures and Algorithms
Data structures in courses/books Trivial Shallow Complex Impractical Theoretically less significant Fibonaacci heap Maximum Flow Algorithm
Data structures • Simple and elegant • Not so difficult to code • Theoretically significant Magical
Organization of the Talk Depth and elegance Range-Minima Dynamic Sequence Dynamic Tree – 1 Dynamic Tree - 2
Part I Range Minima
Range-Minima Given an array A storing numbers, design a data structure to answer a sequence of queries: Range-minima() : report the smallest element from A[],…,A[] () (log ) Space Range-Minima() = -6 () Query time 3 5 1 8 19 0 -1 30 99 -6 10 2 40 27 44 67 A =4 =11
Key idea Tiny data structures A
Details of tiny data structure stored at each 8 4 2 1 A Tiny data structure of Index stores minimum element for {A[],…,A[+ ]} for each ≤
Homework • Preprocessing time : • C code for Range-minima(): Hint: Use auxiliary arrays of size () (log ) lines
Part II Dynamic Sequence
Dynamic Sequences • Report() • Multi-Add() Multi-Add() Report()
Dynamic Sequences Key Idea • Report() • Multi-Add() • Rotate() Binary Search Trees Perform Implicitly () Space () Time per operation (log ) Rotate()
How much do we know about Balanced BST ? The elements with rank in the range [,] : LCA T
How much do we know about Balanced BST ? The elements with rank in the range [,] : LCA T
How much do we know about Balanced BST ? The elements with rank in the range [,] : LCA T
How much do we know about Balanced BST ? (log ) ancestors The elements with rank in the range [,] : (log ) subtrees LCA T
How much do we know about Balanced BST ? (log ) Split(T,x) < < x Merge(T1,x,T2) T2 T1 T
Balanced Binary Tree : Additional information
Dynamic Sequences • Report() • Multi-Add() • Rotate() 0 9 size 5 0 3 0 add 3 0 1 1 0 0 1 0 0 1 1 0 Report()
Dynamic Sequences • Report() • Multi-Add() • Rotate() 0 9 size 5 0 3 0 add 3 0 1 1 0 0 1 0 0 1 1 0 Multi-Add()
Dynamic Sequences • Report() • Multi-Add() • Rotate() 0 9 size 5 0 3 0 add 3 0 1 1 0 0 1 0 0 1 1 0 Multi-Add()
Dynamic Sequences • Report() • Multi-Add() • Rotate() 0 9 size 5 0 3 0 add 3 0 1 1 0 0 1 0 0 1 1 0 Multi-Add()
Dynamic Sequences • Report() • Multi-Add() • Rotate() 0 9 size 5 0 3 0 add 3 0 1 1 0 0 1 0 0 1 1 0 Multi-Add()
Dynamic Sequences • Report() • Multi-Add() • Rotate() 0 9 size 5 0 3 2 add flip 3 1 2 1 0 1 0 0 0 1 1 0 Multi-Add()
Dynamic Sequences • Report() • Multi-Add() • Rotate() 9 0 0 size 5 0 0 0 3 2 add flip 3 1 2 0 0 1 0 0 1 0 0 0 0 0 1 0 0 1 Rotate()
Homework • Details of Rotate() Hint: Use Split and Merge of BST. • Implement one more operation: ReportMin()
Dynamic Trees j g a b f e c d u u v w
Dynamic Trees Aim : Maintain a forest of trees on vertices under the following operations. • Link() : Add an edge between and • Cut() :Delete an edge between and • Information :associated with nodes/edges • Query : • Related to path • Related to entire tree • Topological
Part III Dynamic tree Sleator-TarjanTree with operations on paths
S-Ttreesquery and updates onpaths Operations : Link() Cut() Add-weight-to-path(,): add to weight of each edge on the path between and . ReportMin-wt-on-path() : report min weight edge on the path between and . j g a b 5 17 13 2 41 c e f 7 23 37 d u +10 12 67 32 u v w Time per operation (log ) () ReportMin-wt-edge(a,g) changes ....
Key Idea A tough problem Dynamic trees Generalize ? A simpler instance Dynamic paths
Dynamic paths • Operations : • Link() • Cut() • Add-weight-to-path(,): add to weight of each edge on the path between and . • ReportMin-wt-on-path() : report min weight edge on the path between and . tail head
Data structure for dynamic paths Each operation in O(log )worst case time. (g,h) (d,e) (b,c) (f,g) (e,f) (a,b) (c,d) Similar to Dynamic Sequence a b c d e f g h e c d h a b f g
ST trees • Maintain each tree as a collection of disjoint paths such that each path in a tree is a collection of O(log ) disjoint paths. • Maintain an augmented binary tree data structure for each path. • O() query time O(log ) using weight balanced binary trees.
Homework • How to compute heavy path decomposition of a tree ? • **How to implement Link() efficiently ? Hints: • Updating the heavy path decomposition efficiently. • Need efficient way to change the root. O()
Part IV Dynamic tree Euler-Tour Tree with operations on subtree
ET Treesquery and updates on trees j g a b 17 2 3 5 Operations : Link(u,v) Cut(u,v) Update-node-weight(v,a): weight(v) a Add-weight-to-tree(v, Δ): add Δ to weight of each node of tree containing v. ReportMin(u) : report min weight in the entire tree containing u. 41 f e 7 32 c d -3 12 u 44 15 67 u v w
ET Treesquery and updates on trees ReportMin(v) = 12 j g a b 17 2 3 5 Operations : Link(u,v) Cut(u,v) Update-node-weight(v,a): weight(v) a Add-weight-to-tree(v, Δ): add Δ to weight of each node of tree containing v. ReportMin(u): report min weight in the entire tree containing u 41 f e 7 32 c d -3 12 u 44 15 67 u v w