1 pq trees, pc trees, and planar graphs hsu & mcconnell presented by roi barkan

51
1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

Upload: dustin-andrews

Post on 24-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

1

PQ Trees, PC Trees, and Planar Graphs

Hsu & McConnell

Presented by Roi Barkan

Page 2: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

2

Outline

Planar Graphs Definition Some thoughts Basic Strategy

PC Tree Algorithm Review of PC Trees The Algorithm Complexity Analysis

Page 3: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

3

Planar Graphs

Graphs that can be drawn on a plane, without intersecting edges.

Examples: Borders Between Countries Trees, Forests Simple Cycles

Counter-Examples: K5

K3,3

Page 4: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

4

Basic Non-Planar Graphs

Page 5: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

5

Some Thoughts

Every Non-Planar Has a K5 or K3,3 Subgraph (Kuratowski, 1930)

Articulation Vertices – Divide and Conquer.

The Problem – Cycles Everything else is either inside or outside. Cut-Set Cycle in a Graph– A cycle that

breaks the graph’s connectivity.

Page 6: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

6

More Thoughts

Small Variations on Trees are allowed Connect one vertex to another. Connect all leaves to the root.

“Minimal” Biconnected Tree Biconnected: No Articulation Vertices Root Must Have a Single Child. Connect Root to a Descendant of its Child. Connect All Leaves to Ancestors.

Page 7: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

7

Existing Solutions

Hopcroft & Tarjan – 1974 First Linear Time Solution

PQ-Tree related solutions Early 90’s Fairly complicated

PC-Tree Solution – 1999 Presented here

Page 8: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

8

Our Strategy

Find a Cut-Set Cycle Replace it With a Simple Place-Holder Recursively Work on the Inside and

the Outside of the Graph Put Everything Back Together On Error – Find a Kuratowski Sub-

Graph.

Page 9: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

9

Some Preprocessing

Split by Articulation Vertices DFS Scan the Graph

Reminder: Back-Edges connect vertices with their ancestors.

Label the Vertices According to a Post-Order Traversal of the DFS-Tree

Keep a List of Back-Vertices, Sorted in Ascending (Post-)Order

Page 10: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

10

Data Representation

Same building blocks as in PC-Trees. P-nodes represent regular vertices in the

graph (store their label) C-nodes represent “place-holders” for

cycles Very intuitive: reserves cyclic order of edges.

Each P-node Knows its DFS-Parent, Each Tree-Edge Knows Who’s the Parent

Page 11: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

11

Flow of The Algorithm

On each step we will work on a single back-vertex, according to their order in the list.

Recursion Ends when the list only holds the root. The root has to be a back-vertex When it’s the only back-vertex we know

how to embed the graph

Page 12: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

12

Finding a Cut-Set Cycle

Let i be the current back-vertex. r is i’s son on the path to the back edge.

Let Tr be the DFS-subtree who’s root is r.

We will view Tr as a PC-tree No internal back edges (i is minimal) Back edges to i will be considered full Back edges to ancestors of i will be

considered empty

Page 13: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

13

Full-Partial Labeling

X is a Full Vertex When (deg(x)-1) of its Neighbors are Full

X is an Empty Vertex When (deg(x)-1) of its Neighbors are Empty

X is Partial if it is not Full and not Empty A Terminal Edge Connects Partial

Vertices. Algorithm: Start with Full Leaves, and

Scan Up the PC-Graph

Page 14: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

14

Terminal Path

All Terminal Edges Are Connected Claim: If they do not form a Path

The Graph isn’t Planar. (Proved Later) Claim: If we can’t Flip Full and Empty

Vertices to Opposite side of the Path The Graph isn’t Planar. (Proved Later)

Page 15: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

15

Tr As a PC-Tree

Page 16: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

16

The Actual Cut-Set Cycle

Page 17: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

17

Pitfall

A Vertex can have a degree of 2. It can Full and Empty Ambiguous. Easily detected:

X’s Full Neighbor is the Only One Left on the Update List.

Deg(X) = 2 In That Case – Only X is a Terminal

Node.

Page 18: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

18

Complete Labeling Algorithm

L List of Full Leaves While L is not Empty

X = pop(L) If L is Empty, and X has a neighbor of

degree 2 output X as the Only Terminal Node.

For each Neighbor Y of X Increment Y’s counter. If the counter reached deg(Y)-1 Add Y to L.

Page 19: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

19

Finding The Terminal Path

Climb Up the DFS Tree From All Partial Vertices, in an Interlaced Manner.

Trim a Possible Apex. If We End Up with a Path Output it. If We End Up with a Tree Non-

Planar.

Page 20: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

20

Our Strategy - Reminder

Find a Cut-Set Cycle Replace it With a Simple Place-Holder Recursively Work on the Inside and

the Outside of the Graph Put Everything Back Together On Error – Find a Kuratowski Sub-

Graph.

Page 21: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

21

Place-Holder For A Cycle

Page 22: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

22

Fine Details

Resulting Graph has the Same Number of Edges, But One Less Cycle.

A Vertex of Degree 2 on the Cycle Becomes an Articulation Vertex Avoid it by Contracting The Vertex.

We Want to Avoid Having Neighboring C Nodes Contract them as well

Page 23: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

23

Fine Details (2)

Parent-bits of the edges need to be kept consistent. Actually not very hard. The new C-node is a Child of i. Vertices in the terminal path that lost their

parents are “adopted” by the new C-node Edge contraction is easy to fix.

Page 24: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

24

How It Is Done

Page 25: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

25

How It Is Done (2)

Page 26: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

26

How It Is Done (3)

Page 27: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

27

Another Example

Page 28: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

28

Another Example (2)

Page 29: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

29

Another Example (3)

Page 30: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

30

Another Example (4)

Page 31: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

31

Our Strategy - Reminder

Find a Cut-Set Cycle Replace it With a Simple Place-Holder Recursively Work on the Inside and

the Outside of the Graph Put Everything Back Together On Error – Find a Kuratowski Sub-

Graph.

Page 32: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

32

Recursive Work

The Inner Side of the Cycle is Easy A tree (Tr) where all the leaves, and the

root are connected to a single node – i. The Outer Side is Done Recursively

The new graph has fewer back-edges, and thus is simpler.

Page 33: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

33

Putting It Together

Each Phase Remembers: Contracted Edges The C-node it created

Connecting Inner and Outer Parts is Easy The C-node preserves cyclic order.

Page 34: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

34

Handling Errors

Two Possible Cases: Terminal edges form a tree. Terminal path can’t be flipped correctly.

Basic Idea Walk from i down the tree to problematic

leaves Move up through back edges Down the tree back to i K5 or K3,3

Page 35: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

35

Terminal Edges Form a Tree

Page 36: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

36

Points to Remember

Full Leaves have Back-Edges to i. Empty Leaves have Back-Edges to

ancestors of i. Every C-node in the Graph originated

from a cycle Every path through a C-node, represents

two paths in the original graph.

Page 37: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

37

Paths Through C-Nodes

Page 38: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

38

When W is a P-Node

Page 39: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

39

When W is a C-Node (1)

Page 40: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

40

When W is a C-Node (2)

Page 41: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

41

When W is a C-Node (2.1)

Page 42: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

42

When W is a C-Node (2.2)

Page 43: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

43

A Path that won’t Flip

The Problematic Node is a C-Node Has an Empty and a Full Sub-Tree on

the Same Side of the Path Terminal Edges Lead to Empty/Full

Sub-Trees As Well

Page 44: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

44

A Path That Won’t Flip (2)

Page 45: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

45

Complexity Analysis

Preprocessing DFS Scan Post-order scan of the DFS tree

Actual Processing Finding Terminal Path Splitting Graph, Putting Back Together Ordering Internal Sub-Tree Recursive Call

Page 46: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

46

Complexity Analysis (2)

Preprocessing – Linear Finding Terminal Path

Every Node scanned not on the Terminal Path will be removed from the graph.

Only need to worry about total lengths of terminal paths

Splitting and Joining O(Terminal Path) Sub-Trees Once for each node.

Page 47: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

47

How Long Are The Paths

Vertex is on the Terminal Path Only two are at the edges Linear cost Others lose at least one edge (to full

subtree) O(|E|) total amount

Page 48: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

48

Some Minor Details

Terminal Path Flipping is Easy P-nodes sorted through the labeling

process Flipping done in O(1) due to cyclic lists.

Terminal Path Splitting is Easy Simply use some pointer tricks

Page 49: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

49

Summary

Intuitive, Linear Algorithm to a Non-Trivial Problem

Data Structure Actually Represents the Problem Domain

A Great Way to End A Great Seminar

Page 50: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

50

Questions ?

Page 51: 1 PQ Trees, PC Trees, and Planar Graphs Hsu & McConnell Presented by Roi Barkan

51

Complexity Analysis

Use Amortized Complexity If we work hard in phase i, we make the job

easier for the next phases. Potential Function:

|Gi| – Number of Vertices and Edges in Gi

|Ci| - Number of C-Nodes in Gi

|Pi| - Number of P-Nodes in Gi

, 2 deg 1i

i ix P

M i G C x