Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Test for the Consecutive Ones Property 1/39. Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming.

Similar presentations


Presentation on theme: "A Test for the Consecutive Ones Property 1/39. Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming."— Presentation transcript:

1 A Test for the Consecutive Ones Property 1/39

2 Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming part –2 children for each Q-node 2/39

3 Consecutive 1’s Property of matrices Given a (0,1)- matrix M, does there exist a PERMUTATION of the COLUMINS of M such that the 1’s in the ROWS are consecutive? 1 2 3 4 1 1 0 0 1 0 0 1 0 1 1 0 3 2 1 4 0 1 1 0 0 0 1 1 1 1 0 0 3/39

4 Consecutive requirement on the rows Each row i of M can be viewed as a requirement that those columns with a 1 in row j must be consecutive. Booth and Lueker ﹝ 1976 ﹞ showed that the consecutive ones property can be tested using P-Q trees in linear time. They process the consecutive requirement in a row by row fashion. 4/39

5 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? – standard tree operation In some data structure it is important to specify certain child orders for certain nodes 5/39

6 6/39 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.

7 Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming part –2 children for each Q-node 7/39

8 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 8/39

9 P-Q Trees An Example Q P 12 34 L(T) = { all permutations generated by T } In the example, L(T) = { 1234,1243,4321,3421 } 9/39

10 10 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 A matrix satisfies the COP iff there is a PQ-tree recording all feasible permutations of its column indices

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

12 12 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-tree so that the columns with 1’s in this row are consecutive. –If there is any problem, COP is not satisfied At the end of the iteration, obtain a PQ- tree representing all feasible permutations for rows considered so far.

13 13 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 : not all full or all empty –2. Tree modificationTree modification

14 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. 14/39

15 Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming part –2 children for each Q-node 15/39

16 16 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 (bottom-up) 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.

17 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. 17/39

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

19 19 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 –You don’t have to remember all the templates

20 Templates P 0 & P 1....... P0P0 P1P1 20

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

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

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

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

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

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

27 27 Templates Q 0 & Q 1 Similar to P 0 and P 1... Q0Q0 Q1Q1

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

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

30 頁面頁面 (共3頁)(共3頁) 30/39

31 31

32 32

33 Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming part –2 children for each Q-node 33/39

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

35 Parent Change How often do we need to change the parent pointers? If the original parent is a P-node, then always change parents for the smaller subtree What about the Q-nodes? –In the worst case, could be O(n 2 ) 35

36 Changing the parent for children of a Q-node to another Q-node …… … … …… … … …… Every node in this Q-node needs to change parent pointer in every template operation, the total number of changes could be O(n 2 ), or O(nlog n) if you do the change in a smart way. 36/39

37 Sufficient for each Q-node to keep two children with parent pointers Connect the children of a Q-node using a doubly linked list. Only the two end children have parent pointers. The other nodes must find their parents through list traversal. 37

38 Full children of a Q-node When a child of a Q-node becomes full, but does not have a parent pointer, how does it tell the parent? –Only tell its two neighbors in the list –Full children of a Q-node must be consecutive in the list. 38

39 Merging two Q-nodes There are two ways to merge: –Left-right or –Bottom-top Sufficient to let the end nodes make new friends (extend the linked list) 39


Download ppt "A Test for the Consecutive Ones Property 1/39. Outline Consecutive ones property PQ-trees Template operations Complexity Analysis –The most time consuming."

Similar presentations


Ads by Google