490 likes | 842 Views
PC-Trees vs. PQ-Trees. 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. Q. Q. P. 4. 5. 6. 3. 1. 2. PQ-trees and the COP. 1 2 3 4 5 6.
E N D
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
Q Q P 4 5 6 3 1 2 PQ-trees and the COP 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
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.
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
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. • Each C-node is associated with a circular link-list.
P PQ-trees → PC-trees 1 6 Root Q2 C2 2 Q1 C1 P 5 3 1 2 5 6 3 4 4 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
Cycle View of PC-trees C 1 6 4 P P C 5 2 1 2 3 4 5 6 3
C 1 5 6 PC-trees and the circular ones property 1 2 3 4 5 6 1 1 0 0 0 0 0 1 1 0 0 0 C 1 1 1 1 0 0 P 0 0 0 1 1 1 1 0 0 0 1 1 4 2 1, 5, 6 are consecutive 3 PC-trees can record all feasible circular permutations of the column indices
C Rotation of PC-trees Root C C Root C P P 3 3 1 2 1 2 5 6 5 6 4 4 The “root” concept is not important for PC-trees. It is there to maintain the parent-childrenrelation for efficiency.
PC-trees and the consecutive ones property 1 2 3 4 5 6 C 1 1 0 0 0 0 P 0 1 1 0 0 0 C 1 1 1 1 0 0 0 0 0 1 1 1 4 5 6 3 1 2 PC-trees can also be used to record all feasible permutations for consecutive ones (fix the first column to be 1)
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
The PC-tree algorithm • Node labeling (up to the LCA) • The same as in PQ-tree. Process according to the depth of the tree (the deepest first) • Tree splitting • Create a new C-node • This is also an online algorithm (rows are processed as they are given), but without any templates
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
empty full Our approach:Finding a separating path • Objective: Find a path that separates the full subtrees from the empty ones • Sufficient to find the two end nodes of this path • By changing the root, some parent-child relations have to be changed • Terminal Node • A partial node whose children are either empty or full relative to some rooting
Key observations at every iteration • 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
R The unique terminal path between two terminal nodes u, u’ (I) Case 1. u, u’and R are not on a path empty u m u' full Flippable C-node
R The unique terminal path between two terminal nodes u, u’ (II) Case 2. u, u’and R are on a path, u’ is the LCA When you reach u’, no more full nodes to be processed empty u u' full
3 5 1 Forbidden structures on PC-trees Where 1, 3, 5 are distinct and consecutive 2 4 6 • 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.
3 5 1 Forbidden structures on PC-trees Where 1, 3, 5 are distinct 2 4 6 The following two cases are forbidden for matrices satisfying the CLOP 2. Non-flippable C-node 1. Three terminal nodes When three parents are on a path
Key observations at every iteration • 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
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
The unique terminal path between two terminal nodes empty u m u' full
The path splitting operation Duplicate each P-node that has both a full subtree and an empty subtree m m
Connecting to the new C-node (I)- using the “full side” as an example • 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 u m u'
C C C P P P P 1 2 4 5 7 8 3 6 Connecting to the new C-node (II) 6 3 1 2 4 5 7 8
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)
Template Matching of PQ-trees (I) P P P Q P Q P Q
Template Matching of PQ-trees (II) Here, we only consider the flipping operation and not the tree merging P P P Q P Q P Q V
Column Ordering of PQ-trees P P P Q 1 P Q P 7 2 3 10 18 17 5 6 9 4 8 16 11 12 Q 30 30 13 14 15
P P P Q 1 P Q P 3 2 7 10 18 17 8 9 11 12 6 16 5 4 Q 15 13 14 31
P P P Q P Q P Q P P P Q P Q P Q What has been accomplished by the flipping ?
P P P Q P Q P Q m u’ u Another look at the result of the flipping operation
P2 P5 The corresponding PC-Tree Operation P1 P3 P4
LCA is a full node: No tree modification necessary 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 LCA: The least common ancestor of full leaves
An example for a PC-tree operation equivalent to a template conversion
Complexity Analysis • Want to show the cost is proportional to the # of 1’s in the row (i.e. # of full leaves). • 2-child with parent pointers for each C-node. • 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
How to pass the full node information to the parent? • If a full node has a parent pointer, easy • If this node is on a cycle, then inform its two neighbors • This would help form consecutive segments of full nodes • When every full node of a cycle does that (note that they become full at different time), you should get a consecutive list of full nodes of the cycle
How many edges and links are traversed? • Edges emanating from full nodes • Edges in terminal path empty u m u' full
The cost of link traversal within a C-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 • There can be at most two neighboring children of the C-node being partial
Traversing the full nodes • Every P-node should have has least two children. • Traversal of every full C-node is # of full nodes in the cycle. • So the traversal cost of a full tree is 2 x (# of full leaves)
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'
Charging the Traversal of P-nodes in the terminal path separately • Every time a P-node is traversed in forming the 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! • Link traversal # of full subtrees
C C C 6 3 1 2 4 5 7 8 P P P P 1 2 4 5 7 8 3 6 The cost of path splitting (I) • Instead of connecting the new C-node to each of its children, go around the boundary of the C-node to form its cycle. Each P-node that has both a full subtree and an empty subtree is duplicated
Path splitting and the new C-node The terminal path The new C-node Cost = path traversal + # of P-node duplication
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
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).
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).