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

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

AVL Trees COL 106 Amit Kumar Shweta Agrawal Slide Courtesy : Douglas Wilhelm Harder, MMath, UWaterloo
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 antennas.
1/44 A simple Test For the Consecutive Ones Property.
1 Disjoint Sets Set = a collection of (distinguishable) elements Two sets are disjoint if they have no common elements Disjoint-set data structure: –maintains.
Binary Trees, Binary Search Trees CMPS 2133 Spring 2008.
K-structure, Separating Chain, Gap Tree, and Layered DAG Presented by Dave Tahmoush.
Tirgul 10 Rehearsal about Universal Hashing Solving two problems from theoretical exercises: –T2 q. 1 –T3 q. 2.
1 Theory I Algorithm Design and Analysis (3 - Balanced trees, AVL trees) Prof. Th. Ottmann.
CS 206 Introduction to Computer Science II 09 / 22 / 2008 Instructor: Michael Eckmann.
Data Structures – LECTURE 10 Huffman coding
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.
CSE 326: Data Structures B-Trees Ben Lerner Summer 2007.
Chapter 12 Trees. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Define trees as data structures Define the terms.
Using PQ Trees For Comparative Genomics - CPM Using PQ Trees For Comparative Genomics Gad M. Landau – Univ. of Haifa Laxmi Parida – IBM T.J. Watson.
Data Structures Using C++ 2E Chapter 11 Binary Trees and B-Trees.
B + -Trees COMP171 Fall AVL Trees / Slide 2 Dictionary for Secondary storage * The AVL tree is an excellent dictionary structure when the entire.
Tirgul 6 B-Trees – Another kind of balanced trees.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 20: Binary Trees.
Important Problem Types and Fundamental Data Structures
Advanced Topics in Algorithms and Data Structures 1 An example.
1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan.
Advanced Data Structures and Algorithms COSC-600 Lecture presentation-6.
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.
Simple Efficient Algorithm for MPQ-tree of an Interval Graph Toshiki SAITOH Masashi KIYOMI Ryuhei UEHARA Japan Advanced Institute of Science and Technology.
1 Efficient Subtyping Tests with PQ-Encoding Jan Vitek University of Purdue work of: Yoav Zibin and Yossi Gil Technion — Israel Institute of Technology.
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.
Binary Trees, Binary Search Trees RIZWAN REHMAN CENTRE FOR COMPUTER STUDIES DIBRUGARH UNIVERSITY.
CSIT 402 Data Structures II
Characterizing Matrices with Consecutive Ones Property
1 Binary Trees Informal defn: each node has 0, 1, or 2 children Informal defn: each node has 0, 1, or 2 children Formal defn: a binary tree is a structure.
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
File Organization and Processing Week Tree Tree.
Tree Traversals, TreeSort 20 February Expression Tree Leaves are operands Interior nodes are operators A binary tree to represent (A - B) + C.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Lecture 15 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Binary Search Trees (BST)
PC-Trees & PQ-Trees. 2 Table of contents Review of PQ-trees –Template operations Introducing PC-trees The PC-tree algorithm –Terminal nodes –Splitting.
Indexing Database Management Systems. Chapter 12: Indexing and Hashing Basic Concepts Ordered Indices B + -Tree Index Files File Organization 2.
HeapSort 25 March HeapSort Heaps or priority queues provide a means of sorting: 1.Construct a heap, 2.Add each item to it (maintaining the heap.
Chapter 13 Backtracking Introduction The 3-coloring problem
CS 307 Fundamentals of Computer ScienceRed Black Trees 1 Topic 19 Red Black Trees "People in every direction No words exchanged No time to exchange And.
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!
Chapter 7 Trees_ Part2 TREES. Depth and Height 2  Let v be a node of a tree T. The depth of v is the number of ancestors of v, excluding v itself. 
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.
Leftist Trees Linked binary tree.
Non Linear Data Structure
Data Structure and Algorithms
CSCE 210 Data Structures and Algorithms
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.
PC trees and Circular One Arrangements
ITEC 2620M Introduction to Data Structures
Lectures on Graph Algorithms: searching, testing and sorting
Characterizing Matrices with Consecutive Ones Property
Data Structures Using C++ 2E
Presentation transcript:

A Test for the Consecutive Ones Property 1/39

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

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

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

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

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

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

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

10 Q P Q 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 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 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 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

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

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

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.

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

Templates P 0 & P P0P0 P1P1 20

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

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... 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... Template P4 for ROOT(T,S) when it is a P-node with one partial child...

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

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

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

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

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

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

31

32

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

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.

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

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

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

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

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