Lowest Common Ancestors Two vertices (u, v) Lowest common ancestors, lca (u, v) Example 1 288 34 567 lca (5, 6) = 4 lca (3, 7) = 2 lca (7, 8) = 1 l(v):

Slides:



Advertisements
Similar presentations
CS Fall 2012, Lab 08 Haohan Zhu. Boston University Slideshow Title Goes Here CS Fall 2012, Lab /17/2015 Tree - Data Structure  Basic.
Advertisements

Chapter 10: Trees. Definition A tree is a connected undirected acyclic (with no cycle) simple graph A collection of trees is called forest.
SUNY Oneonta Data Structures and Algorithms Visualization Teaching Materials Generation Group Binary Search Tree A running demonstration of binary search.
Binary Search Trees CSE 331 Section 2 James Daly.
Breadth-First Search of Graphs Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms.
©Brooks/Cole, 2003 Chapter 12 Abstract Data Type.
CMPS 2433 Discrete Structures Chapter 5 - Trees R. HALVERSON – MIDWESTERN STATE UNIVERSITY.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
Constant-Time LCA Retrieval
Advanced Topics in Algorithms and Data Structures 1 Rooting a tree For doing any tree computation, we need to know the parent p ( v ) for each node v.
Breadth First Search
Discrete Mathematics Transparency No. 8-1 Chapter 8 Trees.
Parallel Prefix Computation Advanced Algorithms & Data Structures Lecture Theme 14 Prof. Dr. Th. Ottmann Summer Semester 2006.
Implementation of Graph Decomposition and Recursive Closures Graph Decomposition and Recursive Closures was published in 2003 by Professor Chen. The project.
Rooted Trees. More definitions parent of d child of c sibling of d ancestor of d descendants of g leaf internal vertex subtree root.
Advanced Topics in Algorithms and Data Structures Page 1 An overview of lecture 3 A simple parallel algorithm for computing parallel prefix. A parallel.
Tree Contraction Label leaf nodes 1...n –Rake odd indexed leaf nodes –Left Compress –Right Compress –Left Compress –Right Compress Key: avoid memory conflicts.
The Euler-tour technique
CS 307 Fundamentals of Computer Science 1 Data Structures Review Session 2 Ramakrishna, PhD student. Grading Assistant for this course.
Recursive Graph Deduction and Reachability Queries Yangjun Chen Dept. Applied Computer Science, University of Winnipeg 515 Portage Ave. Winnipeg, Manitoba,
2/10/03Tucker, Sec Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
Lecture 13 CSE 331 Oct 2, Announcements Mid term in < 2 weeks Graded HW2 at the END of the class.
Trees and Tree Traversals Prof. Sin-Min Lee Department of Computer Science San Jose State University.
Chapter Chapter Summary Introduction to Trees Applications of Trees (not currently included in overheads) Tree Traversal Spanning Trees Minimum.
ساختمانهای گسسته دانشگاه صنعتی شاهرود – اردیبهشت 1392.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
The LCA Problem Revisited
Lecture 8 Tree.
Constant-Time LCA Retrieval Presentation by Danny Hermelin, String Matching Algorithms Seminar, Haifa University.
Computer Science: A Structured Programming Approach Using C Trees Trees are used extensively in computer science to represent algebraic formulas;
Chap 8 Trees Def 1: A tree is a connected,undirected, graph with no simple circuits. Ex1. Theorem1: An undirected graph is a tree if and only if there.
Computer Science 112 Fundamentals of Programming II Introduction to Trees.
Trees 2: Section 4.2 and 4.3 Binary trees. Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children
Discrete Mathematics Chapter 5 Trees.
1 Trees 2 Binary trees Section Binary Trees Definition: A binary tree is a rooted tree in which no vertex has more than two children –Left and.
Hello Everyone!!! 1. Tree And Graphs 2 Features of Trees  Tree Nodes Each node have 0 or more children A node have must one parent  Binary tree Tree.
Domain and Range: Graph Domain- Look horizontally: What x-values are contained in the graph? That’s your domain! Range- Look vertically: What y-values.
Discrete Mathematics Chapter 10 Trees.
Chapter 11. Chapter Summary  Introduction to trees (11.1)  Application of trees (11.2)  Tree traversal (11.3)  Spanning trees (11.4)
Chapter 10 Trees © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Succinct Data Structures
CSCE 210 Data Structures and Algorithms
Fundamentals of Programming II Introduction to Trees
Discrete Mathematicsq
Binary search tree. Removing a node
Section 3.3 – Rates of Change and Behavior of Graphs
Paul Tymann and Andrew Watkins
12. Graphs and Trees 2 Summary
Ariel Rosenfeld Bar-Ilan Uni.
Data Structures Review Session 2
Section 8.1 Trees.
Binary Search Tree In order Pre order Post order Search Insertion
Binary Trees, Binary Search Trees
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
Minimum Spanning Tree Verification
Let’s Review Functions
Section 9.3 by Andrew Watkins
Lecture 36 Section 12.2 Mon, Apr 23, 2007
Approximating Points by A Piecewise Linear Function: I
Binary Trees, Binary Search Trees
Trees.
Binary Trees.
Let’s Review Functions
Binary Trees, Binary Search Trees
A Variation of Minimum Latency Problem on Path, Tree and DAG
Let’s Review Functions
A Binary Tree is a tree in which each node has at most 2 children
Presentation transcript:

Lowest Common Ancestors Two vertices (u, v) Lowest common ancestors, lca (u, v) Example lca (5, 6) = 4 lca (3, 7) = 2 lca (7, 8) = 1 l(v): left most appearance of v r(v): right most appearance of v If r(u) < l(v) then lca (u,v) is the vertex with minimum level over the interval [r(u), l(v)] How to find [r(u), l(v)] efficiently?

Range Minima Problem Let {s 1,s 2,s 3,s 4,s 5,s 6,s 7,s 8 } = {5,10,3,4,7,1,8,2} Given i, j, how to find min {a i...a j } in constant time? Approach: Prefix min Suffix min p=[5,5] s=[5,10] p=[7,1] s=[1,1] p=[5,5,3,3] s=[3,3,3,4] p=[7,1,1,1] s=[1,1,2,2] p=[3,3] s=[3,4] p=[8,2] s=[2,2] p=[5,5,3,3,3,1,1,1] s=[1,1,1,1,1,1,2,2] min {a k..a l } 1. Find lca w of a k and a l in a complete binary tree Let x: left child, y: right child of w 2. suffix min of k in x 3. prefix min of l in y 4. take min of 2 and 3 Example {a 3..a 5 } w = v 1 suffix min of 3rd in v 2 = 3 prefix min of 5th in v 3 =7 min {a 3..a 5 } = 3 v1 v2 v3 v4 v5 v6v7

Applications: Computing the minimum of its descendants Example For each v i, compute x i = minimum a j among all its descendants v j of v i Then x i = min {a k.. a j }, where k is preorder (v i ) and j = k + descendants of (v i ) -1

Complexity of Range Minima O ( log n ) time with O ( n ) PEs MergingP [ i.. j] P [ j+1.. k] P’ [ i.. k] parent copy  min ( , p[j+1]) Each level of three O (1) total time O (log n) time for constructing the P, S lists Two part: Initial construction Searching Construction: Searching: Constant time

Breadth First Traversal BFS: 1, 2, 8, 9, 3, 4, 5, 6, level 0 level 1 Eulerian Tour ET = (v1,v2), (v2,v3), (v3,v2), (v2,v4), (v4,v5), (v5,v4), (v4,v6 ), (v6,v4), (v4,v7), (v7,v4), (v4,v2), (v2,v1), (v1,v8), (v8,v1), (v1,v9), (v9,v1)

Generalized Prefix Computation Next class: read section 4.9