PC-Trees & PQ-Trees. 2 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting.

Slides:



Advertisements
Similar presentations
Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees  Recursive definition 1.An empty tree is a binary tree 2.A node.
Advertisements

Chapter 4: Trees Part II - AVL Tree
AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
Dynamic Planar Convex Hull Operations in Near- Logarithmic Amortized Time TIMOTHY M. CHAN.
1/44 A simple Test For the Consecutive Ones Property.
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.
Binary Trees, Binary Search Trees COMP171 Fall 2006.
Balanced Binary Search Trees
A balanced life is a prefect life.
1 Theory I Algorithm Design and Analysis (3 - Balanced trees, AVL trees) Prof. Th. Ottmann.
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.
Transforming Infix to Postfix
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.
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.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
P2P Course, Structured systems 1 Introduction (26/10/05)
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
Building Suffix Trees in O(m) time Weiner had first linear time algorithm in 1973 McCreight developed a more space efficient algorithm in 1976 Ukkonen.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
Binary Trees Chapter 6.
1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan.
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 71 TREE. Binary Tree A binary tree T is a finite set of one or more nodes such that: (a) T is empty or (b) There is a specially designated node.
A Test for the Consecutive Ones Property 1/39. Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming.
MCS 312: NP Completeness and Approximation algorithms Instructor Neelima Gupta
Introduction Of Tree. Introduction A tree is a non-linear data structure in which items are arranged in sequence. It is used to represent hierarchical.
Lecture 10 Trees –Definiton of trees –Uses of trees –Operations on a tree.
Multi-way Trees. M-way trees So far we have discussed binary trees only. In this lecture, we go over another type of tree called m- way trees or 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.
CSIT 402 Data Structures II
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
Data Structures Balanced Trees 1CSCI Outline  Balanced Search Trees 2-3 Trees Trees Red-Black Trees 2CSCI 3110.
Introduction to Planarity Test W. L. Hsu. Plane Graph A plane graph is a graph drawn in the plane in such a way that no two edges intersect A plane graph.
Finding maximal planar subgraphs Wen-Lian Hsu 1/33.
1 Chapter 10 Trees. 2 Definition of Tree A tree is a set of linked nodes, such that there is one and only one path from a unique node (called the root.
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.
2-3 Tree. Slide 2 Outline  Balanced Search Trees 2-3 Trees Trees.
Starting at Binary Trees
Red–black trees.  Define the red-black tree properties  Describe and implement rotations  Implement red-black tree insertion  We will skip red-black.
File Organization and Processing Week Tree Tree.
15-853Page :Algorithms in the Real World Planar Separators I & II – Definitions – Separators of Trees – Planar Separator Theorem.
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
M180: Data Structures & Algorithms in Java Trees & Binary Trees Arab Open University 1.
Chapter 13 Backtracking Introduction The 3-coloring problem
BINARY TREES Objectives Define trees as data structures Define the terms associated with trees Discuss tree traversal algorithms Discuss a binary.
S&H Planarity Test Based on PC-Trees Wen-Lian Hsu.
1 Binary Search Trees  Average case and worst case Big O for –insertion –deletion –access  Balance is important. Unbalanced trees give worse than log.
PC-Trees vs. PQ-Trees. 2 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting.
1/44 A simple Test For the Consecutive Ones Property Without PC-trees!
Red-Black Trees an alternative to AVL trees. Balanced Binary Search Trees A Binary Search Tree (BST) of N nodes is balanced if height is in O(log N) A.
LINKED LISTS.
Database Applications (15-415) DBMS Internals- Part III Lecture 13, March 06, 2016 Mohammad Hammoud.
PC-Trees Based on a paper by Hsu and McConnell. Talk Outline We Define the consecutive ones and circular ones problems We show PQ Trees – the traditional.
PC-Trees & PQ-Trees. 2 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting.
The minimum cost flow problem
Conventions Red edges: traversed tree edges White edges: back edges
Binomial Heaps On the surface it looks like Binomial Heaps are great if you have no remove mins. But, in this case you need only keep track of the current.
B+-Trees.
B+-Trees.
B+ Tree.
PC trees and Circular One Arrangements
Data Structures Balanced Trees CSCI
Ch. 8 Priority Queues And Heaps
Lectures on Graph Algorithms: searching, testing and sorting
Important Problem Types and Fundamental Data Structures
Presentation transcript:

PC-Trees & PQ-Trees

2 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting the terminal path Observations on PC-trees

3 Order of Leaves in a Tree Usually we do not specify the child order in a (rooted) tree –When you lay down a tree on the plane there are many ways to do this so that the leaf orders are different How many different ways can you order the leaves of a tree? In some data structure it is important to specify certain child orders for certain nodes

4 The consecutive ones property (COP) COP : Can one permute the columns of a (0,1)-matrix such that the 1’s in each row are consecutive? One application is in the representation of the matrix, e.g. when you send the matrix through the Internet –Need only to give the “start” and “end” positions of the 1’s for each row, and the column order –O(m+n) space instead of O(mn) for a (m x n) – matrix.

5 PQ-Trees There are many column permutations satisfying the COP One can use a PQ-tree to record all feasible permutations of the column indices –Children order of a P-node can be arbitrary –Children order of a Q-node can only be inverted

6 Q P Q PQ-trees and the COP

7 Linear time algorithm on PQ-trees [1974] Booth and Lueker presented a linear time algorithm for the COP test based on PQ-trees PQ-tree can also be used to yield a linear time algorithm for interval graph recognition and planar graph recognition.

8 Operations on PQ-trees Initially, there is a root P-node with all columns as leaves. Rows are considered one by one. Every time a new row comes in, we need to modify the current PQ-trees so that the columns with 1’s in this row are consecutive. At the end of the iteration, obtain a PQ- tree representing all feasible permutations for rows considered so far.

9 Booth and Lueker’s PQ-Tree algorithm At each iteration consider a new row coming in. It is a bottom-up approach consisting of two stages: –1. Node labelingNode labeling The leaves of the incoming row are labeled full, all the other leaves are empty. the remaining nodes are labeled as follows. empty : all of its children are empty full : all of its children are full partial : neither full nor empty –2. Tree modificationTree modification

10 1. Node labeling (bottom-up) The first time a node u becomes partial or full report to its parent. The first time a node u gets a partial or full child label u partial. The first time all children of a node u become full label u full.

11 2. Tree modification Need to modify the current tree so that all the incoming columns can be arranged consecutively. There is no need to do anything for full subtrees Modify the subtree of every partial node –At each iteration, modify the subtree T of a partial node starting from the lowest level of the tree The purpose is to ensure all full subtrees of T can be arranged consecutively. The subtree modification is based on 9 templates of subtree structures.

12 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting the terminal path Observations on PC-trees

13 Template operations Change the children order so that full nodes become consecutive. Perform this in a bottom-up fashion At each stage, there are 9 templates to check altogether –These templates are, in some sense, minimized.

14 Templates P 0 & P P0P0 P1P1

15... Template P2 for ROOT (T,S) when it is a P-node

16 Q-templates for partial nodes other than the root If the root is the only partial node, use template P2 in the last slide (so the root remains as a P-node). Otherwise, we use Q-node to represent a partial node during the operation so that the Q-templates can be adopted correctly.

17... Template P3 for a singly partial P- node which is not ROOT (T,S) Even though this Q-node has only two children, we still make it a Q-node to facilitate later Q-template operations

18... Template P4 for ROOT(T,S) when it is a P-node with one partial child...

19 Template P5 for a singly partial P-node, other than ROOT(T,S), with one partial child...

20 Template P6 for ROOT(T,S) when it is a doubly partial P-node...

21 Templates Q 0 & Q 1 Similar to P 0 and P 1

22... Template Q2 for a singly partial Q- node

23 Template Q3 for a double partial Q- node...

24 Time complexity of the original PQ-tree operations Because of the frequent change of parent children relations, we can only keep parent pointers for two “end” nodes of each Q-node. This analysis of O(m+n) time is quite involved –Booth & Lueker used amortized analysis to argue that it takes constant time at every iteration. Details will be given later when we discuss the complexity of PC-tree operations.

25 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting the terminal path Observations on PC-trees

26 Circular Ones Property (CLOP) Does there exist a column order such that either –the 1’s in each row are consecutive or –the 0’s in each row are consecutive This would be easy to see if you wrap around the column indices in a circle.

27 PC-Trees A PC-tree is an un-rooted tree with two types of nodes P and C. Neighbors of a P-node can be permuted arbitrarily (Note that here we did not say “children” because there is no specific root). Neighbors of a C-node obey a clockwise order, which can only be inverted.

28 PQ-trees → PC-trees Q1Q1 P Q2Q Root C1C1 P C2C2 If you consider the order of the parent and children of a Q-node in a cyclic fashion, its clockwise order can only be inverted, which is the spirit of a C-node

29 PC-trees and the circular ones property PC-trees can record all feasible circular permutations of the column indices 2 P C C 1, 5, 6 are consecutive

30 Rotation of PC-trees C Root C P C C P 1 The “root” concept is not important for PC-trees. It is there to maintain the parent-children relation for efficiency.

31 PC-trees and the consecutive ones property PC-trees can also be used to record all feasible permutations for consecutive ones (fix the first column to be 1) P C C

32 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting the terminal path Observations on PC-trees

33 The PC-tree algorithm 1.Node labeling The same as in PQ-tree 2.Tree splitting Create a new C-node Same as PQ-tree, this is also an online algorithm (rows are processed as they are given), but without any templates

34 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting the terminal path Observations on PC-trees

35 Objective: Find a path that separates the full subtrees from the empty onesObjective: Find a path that separates the full subtrees from the empty ones –Sufficient to find the two end nodes of this path A rooting of a PC-tree is to assign a node as the root and redirect all parent-child relationsA rooting of a PC-tree is to assign a node as the root and redirect all parent-child relations Terminal NodeTerminal Node –A partial node whose children are either empty or full relative to some rooting Our approach: Finding a separating path empty full

36 Key observations There are at most two terminal nodes –There is a unique tree path between these two nodes Full children of C-nodes on the path can be correctly flipped to one side, and empty ones to the other side

37 The unique terminal path between two terminal nodes u, u’ (I) um u' empty full Flippable C-node R What if node u is a C-node? Case 1. u, u’ and R are not on a path

38 The unique terminal path between two terminal nodes u, u’ (II) u u' R empty full Case 2. u, u’ and R are on a path

39 Forbidden structures on PC-trees Whenever you have such a collection of subtrees, the matrix does not satisfy the CLOP (and hence, does not satisfy the COP). –Why? 1, 3, 5 have to be next to each other. –WLOG, assume the order is 135 where 3 is between 1 and 5. But then, there is no place for 4, which needs to be to the left or right of Where 1, 3, 5 are distinct and consecutive

40 Forbidden structures on PC-trees Three terminal nodes 2. Non-flippable C-node12 Where 1, 3, 5 are distinct When three parents are on a path The following two cases are forbidden for matrices satisfying the CLOP

41 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting the terminal path Observations on PC-trees

42 The unique terminal path between two terminal nodes um u' R empty full

43 The path splitting operation m i m Duplicate each P-node that has both a full subtree and an empty subtree

44 Connecting to the new C-node (I) - using the “full side” as an example um u' All P-nodes on the path connects directly to the new node –obeying the order on the path All C-nodes on the path are deleted. Their children connect directly to the new node –obeying their original order as well as path order

45 Connecting to the new C-node (II) C PP CC P P

A Graphical Illustration of the PQ-Tree Operations vs. the PC-Tree Operations For this example, we only demonstrate the flipping process (but not the merge operation)

47 Template Matching of PQ-trees (I) P Q P PP Q P Q

48 Template Matching of PQ-trees (II) P Q P PP Q P Q V

49 What has been accomplished by the flipping ? P Q P PP Q P Q P Q P PP Q P Q

50 Another look at the result of the flipping operation m R u u’ P Q P PP Q P Q

51 The corresponding PC-Tree Operation P4P4 P1P1 P3P3 P2P2 P5P5

52 LCA: The least common ancestor of full leaves 1.LCA is a full node: No tree modification necessary 2.LCA is a partial node: A child Q-node is created with the full children arranged consecutively (there can be many cases, one example is shown below) The PQ-tree after the modification

53 An example for a PC-tree operation equivalent to a template conversion

54 Complexity Analysis Want to show the cost is proportional to the # of 1’s in the row (i.e. # of full leaves). There is a catch here: for each C-node, we cannot afford to have a parent pointer for each child due to frequent pointer change in path splitting. –Can only keep parent pointer for two “end” nodes –Keep a cycle for each C-node as a double linked list –Internal node of the cycle find parent through neighbors! virtual real

55 The cost of node labeling Easy for P-node; for each internal node of a C-node, inform its two neighbors when it becomes full or partial. –Since full children of a C-node must be consecutive, it is easy to check at the end whether this C-node is full or partial –In case none of the two end nodes are full, this C- node is the LCA. Nothing else needs to be done (similar to the case that the LCA is full)

56 The cost of path splitting (I) Instead of connecting the new C-node to each of its child, go around the boundary of the C-node to form its cycle. C P P C C P P Each P-node that has both a full subtree and an empty subtree is duplicated

57 Path splitting and the new C-node The terminal path The new C-node Cost = path traversal + # of P-node duplication

58 The cost of path splitting (II) Each P-node that has both full subtrees and empty subtrees need to be duplicated –The # of new P-nodes added at each iteration  # of full subtrees Need to worry about the cost of traversing through empty P-nodes

59 A potential problem: what if a cycle contains very few full nodes? The cost of forming this cycle (traversing through empty P-nodes in the cycle) is not proportional to the number of full nodes. u u'

60 Charging the Traversal of empty P-nodes separately Every time an empty P-node is traversed in forming a cycle, its two neighboring tree edges become cycle links Once a tree edge becomes a cycle link, it remains as a link. –Each tree edge can be converted to a link at most once!

61 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting the terminal path Observations on PC-trees

62 Final observations (I) At every iteration, we determine a unique path that separates the tree into “two parts” (for circular ones, the root is immaterial).

63 Final observations (II) The two terminal nodes actually give the two “cuts” in terms of the column partition (when the new row is placed into the current partition).

64