Download presentation
Presentation is loading. Please wait.
Published byRosemary Black Modified over 8 years ago
1
PC-Trees & PQ-Trees
2
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
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
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
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
6 Q P 1 2 3 56 Q 4 1 2 3 4 5 6 1 1 0 0 0 0 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 PQ-trees and the COP
7
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
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
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
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
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
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
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
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
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
16 Templates P 0 & P 1....... P0P0 P1P1
17
17... Template P2 for ROOT (T,S) when it is a P-node
18
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
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
20... Template P4 for ROOT(T,S) when it is a P-node with one partial child...
21
21 Template P5 for a singly partial P-node, other than ROOT(T,S), with one partial child...
22
22 Template P6 for ROOT(T,S) when it is a doubly partial P-node...
23
23 Templates Q 0 & Q 1 Similar to P 0 and P 1
24
24... Template Q2 for a singly partial Q- node
25
25 Template Q3 for a double partial Q- node...
26
頁面頁面 (共3頁)(共3頁)
27
27
28
28
29
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
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
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
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
33 PQ-trees → PC-trees Q1Q1 P 1 2 3 Q2Q2 56 4 1 2 3 5 6 4 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
34 PC-trees and the circular ones property PC-trees can record all feasible circular permutations of the column indices 2 P 1 3 56 4 1 2 3 4 5 6 1 1 0 0 0 0 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 1 1 C C 1, 5, 6 are consecutive
35
35 Rotation of PC-trees 1 2 3 56 4 C Root C P 2 3 56 4 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
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 1 2 3 56 4 1 2 3 4 5 6 1 1 0 0 0 0 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 C C
37
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
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
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
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
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
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
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
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 3.345612 Where 1, 3, 5 are distinct and consecutive
45
45 Forbidden structures on PC-trees3456 1. 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
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
47 The unique terminal path between two terminal nodes um u' R empty full
48
48 The path splitting operation m i m Duplicate each P-node that has both a full subtree and an empty subtree
49
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
50 Connecting to the new C-node (II) C PP CC 154278 6 3 P P 154278 6 3
51
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
52 Template Matching of PQ-trees (I) P Q P PP Q P Q
53
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
54 Column Ordering of PQ-trees P Q P PP Q P Q 1 23 4 56 7 8 9 10 1112 13 14 15 16 17 18
55
55 P Q P PP Q P Q 7 5 4 6 3 2 89 1112 15 14 13 16 10 17 18 1
56
56 What has been accomplished by the flipping ? P Q P PP Q P Q P Q P PP Q P Q
57
57 Another look at the result of the flipping operation m R u u’ P Q P PP Q P Q
58
58 The corresponding PC-Tree Operation P4P4 P1P1 P3P3 P2P2 P5P5
59
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
60 An example for a PC-tree operation equivalent to a template conversion
61
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
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
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 154278 6 3 P P 154278 6 3 Each P-node that has both a full subtree and an empty subtree is duplicated
64
64 Path splitting and the new C-node The terminal path The new C-node Cost = path traversal + # of P-node duplication
65
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
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
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
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
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
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
71
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.