Université de Nantes Dynamic Trees and Log-lists Irena Rusu Université de Nantes, LINA

Slides:



Advertisements
Similar presentations
Introduction to Computer Science 2 Lecture 7: Extended binary trees
Advertisements

Binary Trees CSC 220. Your Observations (so far data structures) Array –Unordered Add, delete, search –Ordered Linked List –??
QuickSort Average Case Analysis An Incompressibility Approach Brendan Lucier August 2, 2005.
Chapter 4: Trees Part II - AVL Tree
AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
I/O-Algorithms Lars Arge Fall 2014 September 25, 2014.
Fusion Trees Advanced Data Structures Aris Tentes.
CS 332: Algorithms Binary Search Trees. Review: Dynamic Sets ● Next few lectures will focus on data structures rather than straight algorithms ● In particular,
B+-Trees (PART 1) What is a B+ tree? Why B+ trees? Searching a B+ tree
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
CS 171: Introduction to Computer Science II
AVL-Trees (Part 1) COMP171. AVL Trees / Slide 2 * Data, a set of elements * Data structure, a structured set of elements, linear, tree, graph, … * Linear:
Data Structures: Trees i206 Fall 2010 John Chuang Some slides adapted from Marti Hearst, Brian Hayes, or Glenn Brookshear.
Chapter 6: Transform and Conquer Trees, Red-Black Trees The Design and Analysis of Algorithms.
AVL-Trees (Part 1: Single Rotations) Lecture COMP171 Fall 2006.
I/O-Algorithms Lars Arge University of Aarhus February 13, 2005.
Amortized Rigidness in Dynamic Cartesian Trees Iwona Białynicka-Birula and Roberto Grossi Università di Pisa STACS 2006.
Trees and Red-Black Trees Gordon College Prof. Brinton.
B + -Trees (Part 1) Lecture 20 COMP171 Fall 2006.
B + -Trees (Part 1). Motivation AVL tree with N nodes is an excellent data structure for searching, indexing, etc. –The Big-Oh analysis shows most operations.
Tirgul 6 B-Trees – Another kind of balanced trees Problem set 1 - some solutions.
AVL Trees / Slide 1 Balanced Binary Search Tree  Worst case height of binary search tree: N-1  Insertion, deletion can be O(N) in the worst case  We.
B + -Trees (Part 1) COMP171. Slide 2 Main and secondary memories  Secondary storage device is much, much slower than the main RAM  Pages and blocks.
CSE 326: Data Structures Lecture #13 Extendible Hashing and Splay Trees Alon Halevy Spring Quarter 2001.
General Trees and Variants CPSC 335. General Trees and transformation to binary trees B-tree variants: B*, B+, prefix B+ 2-4, Horizontal-vertical, Red-black.
David Luebke 1 7/2/2015 ITCS 6114 Binary Search Trees.
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
Important Problem Types and Fundamental Data Structures
Binary Trees Chapter 6.
B-Tree. B-Trees a specialized multi-way tree designed especially for use on disk In a B-tree each node may contain a large number of keys. The number.
Chapter Tow Search Trees BY HUSSEIN SALIM QASIM WESAM HRBI FADHEEL CS 6310 ADVANCE DATA STRUCTURE AND ALGORITHM DR. ELISE DE DONCKER 1.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
1 Data Structures Lists and Trees. 2 Real-Life Computational Problems All about organizing data! –What shape the data should have to solve your problem.
AVL Trees Amanuel Lemma CS252 Algoithms Dec. 14, 2000.
Trevor Brown – University of Toronto B-slack trees: Space efficient B-trees.
Chapter 6 Binary Trees. 6.1 Trees, Binary Trees, and Binary Search Trees Linked lists usually are more flexible than arrays, but it is difficult to use.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
Balancing Binary Search Trees. Balanced Binary Search Trees A BST is perfectly balanced if, for every node, the difference between the number of nodes.
Computer Algorithms Submitted by: Rishi Jethwa Suvarna Angal.
Data Structures Week 8 Further Data Structures The story so far  Saw some fundamental operations as well as advanced operations on arrays, stacks, and.
B + -Trees. Motivation An AVL tree with N nodes is an excellent data structure for searching, indexing, etc. The Big-Oh analysis shows that most operations.
Outline Binary Trees Binary Search Tree Treaps. Binary Trees The empty set (null) is a binary tree A single node is a binary tree A node has a left child.
Search Trees Chapter   . Outline  Binary Search Trees  AVL Trees  Splay Trees.
Data Structure & Algorithm II.  In a multiuser computer system, multiple users submit jobs to run on a single processor.  We assume that the time required.
File Organization and Processing Week Tree Tree.
Union-find Algorithm Presented by Michael Cassarino.
Four different data structures, each one best in a different setting. Simple Heap Balanced Heap Fibonacci Heap Incremental Heap Our results.
Algorithms 2005 Ramesh Hariharan. Divide and Conquer+Recursion Compact and Precise Algorithm Description.
AVL Trees 1. 2 Outline Background Define balance Maintaining balance within a tree –AVL trees –Difference of heights –Rotations to maintain balance.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
AVL Trees / Slide 1 Height-balanced trees AVL trees height is no more than 2 log 2 n (n is the number of nodes) Proof based on a recurrence formula for.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
Amortized Analysis and Heaps Intro David Kauchak cs302 Spring 2013.
8/3/2007CMSC 341 BTrees1 CMSC 341 B- Trees D. Frey with apologies to Tom Anastasio.
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
File Organization and Processing Week 3
Lec 13 Oct 17, 2011 AVL tree – height-balanced tree Other options:
Multiway Search Trees Data may not fit into main memory
B+-Trees.
B+-Trees.
B+-Trees.
Hashing Exercises.
AVL Trees "The voyage of discovery is not in seeking new landscapes but in having new eyes. " - Marcel Proust.
Binary Trees, Binary Search Trees
original list {67, 33,49, 21, 25, 94} pass { } {67 94}
Wednesday, April 18, 2018 Announcements… For Today…
B- Trees D. Frey with apologies to Tom Anastasio
B- Trees D. Frey with apologies to Tom Anastasio
Lecture 10 Oct 1, 2012 Complete BST deletion Height-balanced BST
Presentation transcript:

Université de Nantes Dynamic Trees and Log-lists Irena Rusu Université de Nantes, LINA

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 2 Outline Motivations for an Array-List (but not the Java Collection …) Dynamic Trees A Sequence is a Filiform Tree A Log-List is a Filiform tree too … but Needs Adjustments Conclusion

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 3 Outline Motivations for an Array-List (but not the Java Collection …) Fundamentals: Dynamic Trees Easy observation: A Sequence is a Filiform Tree A step further: A Log-List too … but Needs Adjustments Conclusion

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 4 Problem. Improve the running time of the existing algorithm for sorting a permutation P by prefix reversals and prefix transpositions (explained below). Motivations for an Array-List P: P: P 8 -1 needed Need to: Reverse Update some P i -1 P: =8 P 8 -1 better using arrays, reverse better using double-linked lists, update ??? Prefix reversal

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 5 Motivations for an Array-List P: P: P: P 1 -1,P 8, P 4 -1 needed Prefix transposition Need to: Transpose Update many P i Update many P i -1 P 1 -1, P 8, P 4 -1 better using arrays, transpose better using double-linked lists, update ??

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 6 Goal: –choose and perform a reversal or transposition in O(log n) –improve the running time of the sorting algorithm from O(n 2 ) to O(n log n) Use trees: Initial step: the permutation is a big tree Coloring step: cut the big tree into subtrees Block operation: change trees order and/or left-right orientation, and globally modify P and P -1 values at the root Final step: link subtrees Motivations for an Array-List : An Idea P:

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 7 Motivations for an Array-List : An Idea P: Trees need to support: Cut several edges Link several subtrees Left-right flipping in O(log n) Binary balanced trees : Height balanced trees Red-Black trees … (Any other with height in O(log n), and which supports re-balancing)

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’ A C B 0 0 A C B 1 Rappels Height-balanced tree Red-black tree (Re-)balance

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 9 Motivations for an Array-List : An Idea P: Trees need to support: Cut several edges Link several subtrees Left-right flipping in O(log n) … but also global modifications of P and P -1 values Binary balanced trees : Height balanced trees Red-Black trees … (Any other with height in O(log n), and which supports re-balancing) ?

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 10 Outline Motivations for an Array-List (but not the Java Collection) Dynamic Trees Easy observation: A Sequence is a Filiform Tree A step further: A Log-List too … but Needs Adjustments Conclusion

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 11 Dynamic trees: Introduction (1) Daniel D. Sleator and Robert E. Tarjan (1983) Data structure proposed to maintain a forest of vertex disjoint rooted trees under link (add an edge) and cut (delete an edge) operations between trees, in O(log n) each. Applications: –maximum flow problem and variants (Sleator, Tarjan, 1983) –the Least Common Ancestor problem (Sleator, Tarjan, 1983) –the transshipment problem (Sleator, Tarjan, 1983) –the string matching problem in compressed strings (Farach, Thorup, 1995) –…

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 12 Dynamic trees: Introduction (2) More precisely, do in O(log n), given the forest of dynamic trees: dparent(v): return the parent of v in its tree, or null droot(v): return the root of the tree containing v dcost(v): return the cost of the edge (v,dparent(v)) dmincost(v): return the vertex w closest to droot(v) whose dcost(w) is minimum on the path from v to droot(v). dupdate(v,u): add u to all costs on the path from v to droot(v) dlink(v,w,u): add edge (v,w) of cost u assuming v = droot(v), thus making w the parent of v dcut(v): delete the edge (v,parent(v)) and return its cost devert(v): make v become the root of its tree Note. All these are operations on paths towards the root a b g c d h e f k l m

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’ A tree is partitionned into « solid » paths going towards the root (edges are « solid » or « dashed ») Dynamic trees: Ideas a b g c d h e f k l m a b c d h e g k m l 2. Each « solid » path is represented as a (particular) binary tree. f

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 14 Dynamic trees: Ideas a b g c d h e f k l m a b c d h e g k m l f Here, the path from k to the root. 3. Operations on paths towards the root: turn the concerned path into a solid path, and perform operations on its binary tree

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’ Operations on paths towards the root: turn the concerned path into a solid path, and perform operations on its binary tree Dynamic trees: Ideas a b g c d h e f k l m a b c d h e g k m l Here, the path from k to the root. f

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 16 Here, the path from k to the root. Dynamic trees: Ideas a b g c d h e f k l m a b c d h e g k m l f Splice : switches one solid and one dashed arc Needs O(log n) for binary balanced trees. Expose : builds the entire path, uses t splices Needs O(t log n) for binary balanced trees. 3. Operations on paths towards the root: turn the concerned path into a solid path, and perform operations on its binary tree

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 17 Dynamic trees: Choose the appropriate solid paths and binary trees Trees Solid paths Standard balanced binary trees Locally biased binary trees/ Splay trees Globally biased binary trees Initial: Arbitrary Later: As resulting from the operations performed Initial and Later: Defined by the structure of the tree (Heavy/light edges*) Running time of expose O(log 2 n) amortized O(log n) amortized O(log n) *(v,father(v)) is a heavy edge in the dynamic tree if 2*size(v)>size(father(v)), where size(v)=#nodes in the tree rooted at v

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 18 Dynamic trees: Choose the appropriate solid paths and binary trees *(v,father(v)) is a heavy edge in the dynamic tree if 2*size(v)>size(father(v)) Lemma. With solid paths defined by the heavy edges, a path from v to droot(v) contains at most log n dashed edges. Lemma. With globally biased binary trees, the running time of one splice operation is not constant, but summing over all splices, the total running time of expose is in O(log n).

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 19 Say v=a, and assume expose(a) has been done. Dynamic trees: Focus on some operations a b c d h a b h c d dparent(a) droot(a) dcost(a) dmincost(a) dupdate(a,u) dlink(v,c,u) dcut(c) devert(c) Search the binary tree Store relative information at nodes and act on the root Cut/link/reverse/balance the binary trees → whatever the type of the tree, it will have a lot of links and information at nodes

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 20 Cost-related information in the binary tree. Dynamic trees: Focus on dcost(), dmincost(), dupdate() a b c d h =cost-mintree =mintree-mintree(bparent()) 5-2=3 2-2=0 5-5=0

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 21 OperationValueComputation dmincost(a)mintree(r)Search the node (one branch) dcost(a)netcost(a,b)+ mintree(a,b) netcost(a,b)+ ∑ w=e,..,r netmin(w) dupdate(a,x)+u on all costs +u on netmin(r) Dynamic trees: Focus on dcost(), dmincost(), dupdate() =cost-mintree =mintree-mintree(bparent()) r Notes. 1) *u on netmin(r) does not multiply all the values 2) several costs are possible

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 22 Dynamic trees: Conclusions (1) With heavy/light edges and globally biased binary trees: –Good news: All the operations are in O(log n) –Principle: Create the solid path from v to r, then work on the associated binary tree –Local operations dparent(v), droot(v) search the binary tree –Aggregate operations dcost(v), dmincost(v), update(v,u) store relative information at nodes and sometimes search the binary tree –Operations dlink(v,w,u), dcut(v), devert(v) modifying the structure of the forest link, cut, reverse, re-balance the binary trees involved. –Several costs are possible

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 23 Dynamic trees: Conclusions (2) Cannot be used in all situations: –Not adapted to top-down visiting the dynamic trees –Not adapted to searching a value in the forest/a dynamic tree –Aggregate operations do not allow multiplications

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 24 Outline Motivations for an Array-List (but not the Java Collection) Fundamentals: Dynamic Trees A Sequence is a Filiform Tree A step further: A Log-List too … but Needs Adjustments Conclusion

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 25 A sequence is a filiform tree: Implement a sequence as a dynamic tree P: a b c d h e f g k l Dynamic tree L associated with P The index i is a new cost. head(L) tail+(L) tail(L) We need to: Compute P i, P i -1 (fixed i) Perform a reversal Perform a transposition Update all P j, P j -1 in O(log n)

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 26 A sequence is a filiform tree: what we get from dynamic trees P: a b c d h e f g k l Dynamic tree L associated with P The index i is a new cost. head(L) tail+(L) tail(L) t8(x=8) t1(y=1) devert, dcut, dlink dmincost, dupdate Not done yet with dynamic trees Note. get_element(), succ(), prev() in O(log n) We are able to do more (tx,ty designate nodes with edge costs x, y) : insert(L,L 1,tx) delete(L,tx,ty) reverse(L,tx,ty) find_min(L,tx,ty) (or max) add(L,tx,ty,u) change_sign(L,tx,ty) find_rank(L,tx) (=P -1 [x]) find_element(L,i) (=P[i]) in O(log n)

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’ )Perform 2)Update the index for delete, insert, reverse A sequence is a filiform tree: what remains to be done Not done yet with dynamic trees change_sign(L,tx,ty) find_rank(L,tx) (=P -1 [x]) find_element(L,i) (=P[i])

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 28 Outline Motivations for an Array-List (but not the Java Collection) Fundamentals: Dynamic Trees Easy observation: A Sequence is a Filiform Tree A Log-List is a filiform tree too … but Needs Adjustments Conclusion

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’ )Perform Quite easy : find_element(L,i) devert(tail+(L)) put the list in its standard from expose(head(L)) all the list is a solid path with binary tree B New: dsearchindex(B,i) search i in the binary search tree B with values index() A log-list is a filiform tree too: Adjustments (1) Not done yet with dynamic trees change_sign(L,tx,ty) find_rank(L,tx) (=P -1 [x]) find_element(L,i) (=P[i]) Time: O(log n)

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 30 change_sign(L,tx,ty): devert(dparent(ty)), expose(tx) (→binary tree B) dminuscost(B) New Idea: (±)binary tree A log-list is a filiform tree too a b c d h Multiply by -1: Change the marks on the roots cost() -cost() Time: O(log n)

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 31 A log-list is a filiform tree too: Adjustments(1ter) P: a b c d h e f g k l tail+(L) tail(L) find_rank(L,tx) devert(tail+(L)) return dindex(tx) How to find tx, given x ? Idea: Nodes a, b, c, … are fixed memory cases Each of them may be a landmark for a given element (i.e. it is kept close to the element) h c d a b Lm t8(x=8)

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 32 A log-list is a filiform tree too: Adjustments(1ter) P: a b c d h m g f k=e l tail+(L) Idea: Nodes a, b, c, … are fixed memory cases Each of them may be a landmark for a given element (i.e. it is kept close to the element) … with a few exceptions at the endpoints of the moved blocks Lm e f g k reversal Lm[x] is one of the endpoints of the edge with cost x; tx is the lowest endpoint of it Time: O(log n)

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 33 A log-list is a filiform tree too: Adjustments(2) a b c d h m g f k=e l tail+(L) e f g k reversal 2) Update the index for delete, insert, reverse m g f k=e Index*(-1) Index+14 g f k=e An example for reverse Time: O(log n) m

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 34 A log-list is a filiform tree too: Summary What is a log-list ? –a filiform dynamic tree L (but temporarily a forest of such trees) –three pointers head(L), tail(L), tail+(L) –a toolbox of O(log n) time operations – (if needed) a landmark table Lm (allows to compute tx) get_element(tx) succ(tx) prec(tx) insert(L,L 1,tx) delete(L,tx,ty) reverse(L,tx,ty) find_min(L,tx,ty) (or max) add(L,tx,ty,u) change_sign(L,tx,ty) find_rank(L,tx) (=P -1 [x]) find_element(L,i) (=P[i])

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 35 A log list is a filiform tree too: Summary Shall we deduce that visiting all the elements in a log-list takes O(n log n)? No, visiting directly the binary tree allows to do this in O(n) … but needs to go deeper into the implementation What about searching a given element in a log-list? If the list is not ordered, O(n) as above If the list is ordered and has distinct elements, the dynamic tree operation dsearchcost (we used it only for cost=index) does it in O(log n).

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 36 Outline Motivations for an Array-List (but not the Java Collection) Fundamentals: Dynamic Trees Easy observation: A Sequence is a Filiform Tree A step further: A Log-List is a filiform tree too … but Needs Adjustments Conclusion

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 37 Conclusion Improving the algorithm for sorting by prefix reversals and prefix transpositions –n steps, each identifying and performing a block operation –O(n log n) time instead of O(n 2 ) before In addition: four other variants of the sorting problem are improved Some of them resist however Log-list could have many other applications

Université de Nantes Dynamic Trees and Log-Lists – I. Rusu – JGA’15 38 Bibliography Daniel D. Sleator and Robert E. Tarjan – A Data Structure for Dynamic Trees, Journal of Computer and System Sciences 26, (1983) Irena Rusu – Log-Lists and Their Applications to Sorting by Transpositions, Reversals and Block-Interchanges, arXiv (2015). Thank you !