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
AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
Advertisements

1/44 A simple Test For the Consecutive Ones Property.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
A balanced life is a prefect life.
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.
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.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
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.
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.
Multiway Trees. Trees with possibly more than two branches at each node are know as Multiway trees. 1. Orchards, Trees, and Binary Trees 2. Lexicographic.
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.
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.
Starting at Binary Trees
Review 1 Queue Operations on Queues A Dequeue Operation An Enqueue Operation Array Implementation Link list Implementation Examples.
PC-Trees & PQ-Trees. 2 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting.
Chapter 13 Backtracking Introduction The 3-coloring problem
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.
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.
Indexing Structures for Files
Non Linear Data Structure
Multiway Search Trees Data may not fit into main memory
The minimum cost flow problem
UNIT III TREES.
Conventions Red edges: traversed tree edges White edges: back edges
Extra: B+ Trees CS1: Java Programming Colorado State University
B+-Trees.
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
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
(edited by Nadia Al-Ghreimil)
TREES General trees Binary trees Binary search trees AVL trees
Monday, April 16, 2018 Announcements… For Today…
Data Structures Balanced Trees CSCI
Database Applications (15-415) DBMS Internals- Part III Lecture 15, March 11, 2018 Mohammad Hammoud.
Breadth-First Search (BFS)
Multi-Way Search Trees
Ch. 8 Priority Queues And Heaps
Lectures on Graph Algorithms: searching, testing and sorting
Topic 23 Red Black Trees "People in every direction No words exchanged No time to exchange And all the little ants are marching Red and Black.
B+-Trees (Part 1).
A Robust Data Structure
Lecture 12 CS203 1.
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
B-Trees Disk Storage What is a multiway tree? What is a B-tree?
(edited by Nadia Al-Ghreimil)
Important Problem Types and Fundamental Data Structures
B+-trees In practice, B-trees are not used much as defined earlier.
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 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

15 Motivation behind the templates By the previous observation, if the LCA is a full node, there would be no tree modification. Otherwise, one would have a partial node. Each template guarantees that after the tree modification, the full subtrees would be arranged consecutively. –Template P2 is a special case where the LCA has only one full child. In template P3, there are full nodes in other subtrees not shown. –In all other cases, you would get a partial Q-node

16 Templates P 0 & P P0P0 P1P1

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

18 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.

19... Template P3 for a singly partial P- node which is not ROOT (T,S) Note that, in this case, there are full leaves in other subtrees not shown in the picture, different from P2

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

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

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

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

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

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

頁面頁面 (共3頁)(共3頁)

27

28

29 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.

30 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

31 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 It would be easy to see if you wrap around the column indices in a circle.

32 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.

33 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

34 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

35 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.

36 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

37 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

38 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

39 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

40 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

41 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

42 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

43 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

44 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

45 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

46 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

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

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

49 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

50 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)

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

53 Template Matching of PQ-trees (II) P Q P PP Q P Q V Here, we only consider the flipping operation and not the tree merging

54 Column Ordering of PQ-trees P Q P PP Q P Q

55 P Q P PP Q P Q

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

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

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

59 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

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

61 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

62 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)

63 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

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

65 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

66 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'

67 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!

68 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

69 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).

70 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).

71