on cartesian trees lowest common ancestors and range
play

On Cartesian Trees, Lowest Common Ancestors, and Range Minimum - PowerPoint PPT Presentation

On Cartesian Trees, Lowest Common Ancestors, and Range Minimum Queries 0 2 0 4 3 5 1 7 6 1 2 min? 3 6 4 5 7 LCA? Parallel Computing Day Ben-Gurion University Tuesday, October 20, 2009 RMQ 2 0 4 3 5 1 7 6 Tuesday,


  1. Parallel RMQ [Berkman and Vishkin 1993] • Min of n elements in O(1) time using n 2 processors [Valiant 1975] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  2. Parallel RMQ [Berkman and Vishkin 1993] • Min of n elements in O(1) time using n 2 processors [Valiant 1975] • O(1) RMQ using n 4 processors 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  3. Parallel RMQ [Berkman and Vishkin 1993] • Min of n elements in O(1) time using n 2 processors [Valiant 1975] • O(1) RMQ using n 4 processors • O(1) RMQ using n 2.5 processors √ n √ n √ n √ n 0 0 1 2 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  4. Parallel RMQ [Berkman and Vishkin 1993] • Min of n elements in O(1) time using n 2 processors [Valiant 1975] • O(1) RMQ using n 4 processors • O(1) RMQ using n 2.5 processors • O(1/ ε ) RMQ using n 1+ ε processors √ n √ n √ n √ n 0 0 1 2 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  5. Parallel RMQ 1 [Berkman and Vishkin 1993] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  6. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  7. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  8. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  9. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  10. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  11. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 Tuesday, October 20, 2009

  12. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 • n log 3 n processors, O(1) time, O(1) query Tuesday, October 20, 2009

  13. Parallel RMQ 1 [Berkman and Vishkin 1993] • Min of n integers each between 1 and n in O(1) time using n processors [Fich, Ragde and Wigderson 1984] 1 0 1 2 3 2 1 0 1 2 1 2 3 4 5 4 3 2 3 4 • n log 3 n processors, O(1) time, O(1) query • n α k ( n ) processors, O(k) time, O(k) query Tuesday, October 20, 2009

  14. Problems with RMQ 1 • RMQ LCA RMQ 1 2 0 4 3 5 4 7 0 5 6 1 4 8 6 7 3 4 2 5 4 Tuesday, October 20, 2009

  15. Problems with RMQ 1 • RMQ LCA RMQ 1 • inefficient in parallel • inefficient in terms of cache-misses (can’t be done via scans) 2 0 4 3 5 4 7 0 5 6 1 4 8 6 7 3 4 2 5 4 Tuesday, October 20, 2009

  16. Problems with RMQ 1 • RMQ LCA RMQ 1 • inefficient in parallel • inefficient in terms of cache-misses (can’t be done via scans) ¼ log n ¼ log n ¼ log n ¼ log n 0 0 1 2 2 0 4 3 5 4 7 0 5 6 1 4 8 6 7 3 4 2 5 4 • # different Blocks = # different Cartesian trees = 4 ¼ log n = √ n [Fischer, Heun 2006] Tuesday, October 20, 2009

  17. Problems with RMQ 1 • RMQ LCA RMQ 1 • inefficient in parallel • inefficient in terms of cache-misses (can’t be done via scans) ¼ log n ¼ log n ¼ log n ¼ log n 0 0 1 2 2 0 4 3 5 4 7 0 5 6 1 4 8 6 7 3 4 2 5 4 • # different Blocks = # different Cartesian trees = 4 ¼ log n = √ n [Fischer, Heun 2006] • Lookup table: index, construct Tuesday, October 20, 2009

  18. Cache-Oblivious RMQ [Demaine, Landau and W. 2009] • An optimal RMQ solution that only makes sequential scans O( n ) prep. O(1) query (serial algorithm) Tuesday, October 20, 2009

  19. A Cache-Oblivious Cartesian Tree ¼ log n 2 0 4 3 5 1 7 6 Tuesday, October 20, 2009

  20. A Cache-Oblivious Cartesian Tree 0 1 2 ¼ log n 3 6 2 0 4 3 5 1 7 6 4 5 7 Tuesday, October 20, 2009

  21. A Cache-Oblivious Cartesian Tree 0 1 2 ¼ log n 3 6 2 0 4 3 5 1 7 6 4 5 7 • cache-oblivious stack holds rightmost path Tuesday, October 20, 2009

  22. A Cache-Oblivious Cartesian Tree 0 1 2 ¼ log n 3 6 2 0 4 3 5 1 7 6 4 5 7 • cache-oblivious stack holds rightmost path ... • when we climb (pop) i vertices, concatenate 0111 11 { i Tuesday, October 20, 2009

  23. A Cache-Oblivious Cartesian Tree 0 1 2 ¼ log n 3 6 2 0 4 3 5 1 7 6 4 5 7 ... ... ... ... 011 1011 1011 1011 1 { { { { i 4 i 1 i 3 i 2 • cache-oblivious stack holds rightmost path ... • when we climb (pop) i vertices, concatenate 0111 11 { i Tuesday, October 20, 2009

  24. A Cache-Oblivious Cartesian Tree 0 1 2 ¼ log n 3 6 2 0 4 3 5 1 7 6 4 5 7 [ ] i 4 ∈ ... ... ... ... 011 1011 1011 1011 1 √ n { { { { i 1 i 3 i 2 • cache-oblivious stack holds rightmost path ... • when we climb (pop) i vertices, concatenate 0111 11 { i Tuesday, October 20, 2009

  25. A Cache-Oblivious Cartesian Tree 0 1 2 ¼ log n 3 6 2 0 4 3 5 1 7 6 4 5 7 min? • ∀ binary string and ∀ query: [ ] i 4 ∈ ... ... ... ... 011 1011 1011 1011 1 √ n { { { { i 1 i 3 i 2 • cache-oblivious stack holds rightmost path ... • when we climb (pop) i vertices, concatenate 0111 11 { i Tuesday, October 20, 2009

  26. A Cache-Oblivious Cartesian Tree 0 1 2 ¼ log n 3 6 2 0 4 3 5 1 7 6 4 5 7 min? • ∀ binary string and ∀ query: [ ] i 4 ∈ 011 ⋄⋄⋄ 1011 ⋄⋄⋄ 1011 ⋄⋄⋄ 1011 ⋄⋄⋄ 1 √ n { { { { i 1 i 3 i 2 • cache-oblivious stack holds rightmost path ... • when we climb (pop) i vertices, concatenate 0111 11 { i Tuesday, October 20, 2009

  27. RMQ Generalization I : A Cartesian Tree of a Tree [Demaine, Landau and W. 2009] Tuesday, October 20, 2009

  28. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph Tuesday, October 20, 2009

  29. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path Tuesday, October 20, 2009

  30. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] Tuesday, October 20, 2009

  31. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  32. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] 5 1 2 6 v 3 6 3 u Tuesday, October 20, 2009

  33. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] 5 1 2 6 v 3 6 3 u Tuesday, October 20, 2009

  34. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 5 1 2 6 v 3 6 3 u Tuesday, October 20, 2009

  35. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 5 1 2 6 v 3 6 3 u 5 Tuesday, October 20, 2009

  36. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 5 1 2 6 6 v 3 6 3 u 5 Tuesday, October 20, 2009

  37. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem O( n α k ( n )) prep. O( k ) query [Alon and Schieber 1987] 5 1 Ω ( n α k ( n )) prep. for O( k ) query [Pettie 2002] 2 6 3 6 3 Tuesday, October 20, 2009

  38. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  39. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  40. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  41. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  42. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  43. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  44. RMQ Generalization I : A Cartesian Tree of a Tree • The Bottleneck Edge Query problem (RMQ on graphs\trees): • preprocess an edge-weighted graph • query asks for max flow that can be routed between u,v along any simple path • Undirected graphs: solve problem on the Maximum Spanning Tree [Hu 1961] • The Minimum Spanning Tree Verification problem 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  45. RMQ Generalization I : A Cartesian Tree of a Tree • Construct Cartesian tree of an input tree in O( n + sort(edges)) 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  46. RMQ Generalization I : A Cartesian Tree of a Tree • Construct Cartesian tree of an input tree in O( n + sort(edges)) • Tight lower bound 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  47. RMQ Generalization I : Compared to AlonSchieber • Construct Cartesian tree of an input tree in O( n + sort(edges)) • Tight lower bound 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  48. RMQ Generalization I : Compared to AlonSchieber • Construct Cartesian tree of an input tree in O( n + sort(edges)) • Tight lower bound • Linear-time if edge-weights are sorted or integers 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  49. RMQ Generalization I : Compared to AlonSchieber • Construct Cartesian tree of an input tree in O( n + sort(edges)) • Tight lower bound • Linear-time if edge-weights are sorted or integers • Otherwise we get linear-space, O( n log [ k ] n ) prep. O( k ) query 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  50. RMQ Generalization I : Compared to AlonSchieber • Construct Cartesian tree of an input tree in O( n + sort(edges)) • Tight lower bound • Linear-time if edge-weights are sorted or integers • Otherwise we get linear-space, O( n log [ k ] n ) prep. O( k ) query • Maintain dynamic Cartesian tree and LCA info 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

  51. RMQ Generalization I : Compared to AlonSchieber • Construct Cartesian tree of an input tree in O( n + sort(edges)) • Tight lower bound • Linear-time if edge-weights are sorted or integers • Otherwise we get linear-space, O( n log [ k ] n ) prep. O( k ) query • Maintain dynamic Cartesian tree and LCA info • Distributed: LCA labeling of the Cartesian tree 1 1 5 1 2 6 3 6 3 Tuesday, October 20, 2009

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend