A Unified View of Graph Searching Derek G. Corneil Richard Krueger.

39
A Unified View of Graph Searching Derek G. Corneil Richard Krueger

Transcript of A Unified View of Graph Searching Derek G. Corneil Richard Krueger.

A Unified View of Graph Searching

Derek G. Corneil

Richard Krueger

Outline

Goal and Motivation Definitions and Notations Graph Searching Characterization –

Basic line Generic Searching BFS LexBFS DFS LexDFS MNS

Conclusions

Goal and Motivation

Graph Search algorithms are commonly used.

The search is being applied through the neighborhood of the vertices. Each edge is traversed exactly once, and we eventually reach all vertices.

The algorithms are varied in selection of the next edge to traverse.

Goal and Motivation

Searching the graph creates an order of the vertices.

We can characterize the search algorithm by exploring the nature of the order it creates.

Such characterization can help us reveal the structure of a graph.

For example, the characterization of LexBFS helps in proving that the reverse of LexBFS-ordering of a chordal graph is a perfect elimination ordering.

Definitions and Notations

All related graphs are connected and undirected. = (v1,…, vn) – linear ordering of V. (i) = vi and -1(vi( = I – refer to a specific vertex in . G[i] = G[v1,…,vi] – be the subgraph of G induced on

a prefix of Chordal graph – every cycle of length at least 4 has

at least one chord. Simplicial vertex – its neighborhood is a clique in G. Perfect Elimination Order – ordering (v1,…,vn) of V of

G, where vi is simplicial in gi.

Graph Searching Characterization - Basic Line

a b c

If a < b < c and acE and abE, then how could vertex b have been chosen before vertex c by our search ?

Generic Search Algorithm

The data structure S is generic “set” to store the candidate vertices.

Input : a graph G = (V, E) and start vertex s Ouput : an ordering of V

1. S {s}

2. For i 1 to n do1. Pick and remove an unnumbered vertex v from S

2. (i) v

3. Foreach unnumbered vertex w adjacent to v do1. Add w to S

Generic Search Characterization

(S): given an ordering of V, if a < b < c and acE and abE, then there exists a vertex d < b such that dbE.

a d b c

Generic Search Characterization

= (1,2,4,3,5,6) is a valid search-ordering of the 3-sun, but this ordering is neither DFS nor BFS.

By using more restrictive data structure we may obtain other properties for our search.

1

4

3

5 6

2

Generic Search Characterization Theorem – For an arbitrary graph G, an

ordering of V is a search-ordering of G if and only if has property (S).

Proof : At the point when b is chosen, both b and c

must be in S. Therefore some neighbor of b must already been chosen, call it d. Thus d < b and dbE. This holds for all triples in , so property (S) holds on .

Generic Search Characterization suppose for contradiction that given , an order

which respect property (S), vi is the first vertex in that can’t be chosen next by the algorithm. So, vi is not in S yet.

Let u be the next vertex the algorithm choose. So, u is in S.

Let w be neighbor of u which caused him to be added to S. So, wuE, but wviE.

By applying (S) on the triple (w,vi,u), there exists d < vi with dviE.

Hence viS, so it could be chosen next. A Contradiction.

BFS – Breadth First Search

BFS is a restriction of generic search in that it explores all neighbors of a selected vertex before it goes deeper in the graph.

It uses queue as its data structure to obtain the restriction.

However, it does not determine which order to push the neighbors of a chosen vertex.

BFS Algorithm

The data structure S is a queue. Input : a graph G = (V, E) and start vertex s Ouput : an ordering of V1. S {s}2. For i 1 to n do

1. pop v from S2. (i) v3. Foreach unnumbered vertex w adjacent to v do

If w is not already in S then push w to S

BFS Characterization

(B): given an ordering of V, if a < b < c and acE and abE, then there exists a vertex d < a such that dbE.

d a b c

BFS Characterization

Theorem – For an arbitrary graph G, an ordering of V is a BFS-ordering of G if and only if has property (B).

Proof : At the point when b is chosen, both b and c

must be in S. Therefore some neighbor of b was pulled from S as least as early as a, call it d. since b does not have a as a neighbor d must be earlier than a.

BFS Characterization

suppose for contradiction that given vi is the first vertex in that can’t be chosen next by the algorithm. So vi is not in S yet.

Let u be the next vertex the algorithm choose, So there is a w < vi adjacent to u but not to vi. Choose w to be the leftmost such vertex in .

By applying (B) on the triple (w,vi,u), there exists d < vi with dviE.

Since w was chosen leftmost, any vertex left to w which is adjacent to u must also be adjacent to v i.

But d is left of w and adjacent to vi, therefore a BFS could choose vi before u.

A Contradiction.

LexBFS – Lexicographic BFS

LexBFS is a BFS with another restriction. It creates an order between the neighbors of

a selected vertex using lexicographic labeling of the vertices through the search.

LexBFS Algorithm

Input : a graph G = (V, E) and start vertex s Ouput : an ordering of V

1. Assign the label 0 to all vertices

2. Label(s) {n+1}

3. For i 1 to n do1. Pick an unnumbered vertex v with lexicographically

largest label

2. (i) v

3. Foreach unnumbered vertex w adjacent to v do Append (n-i) to label(w)

LexBFS Example

1

4

3

5 6

2

= { }

000

0 0

06

5 5

= { 1 } = { 1 2 }

4 4

5 4

= { 1 2 3 }

34 3

= { 1 2 3 5 }

3 24 2

= { 1 2 3 5 4 } = { 1 2 3 5 4 6 }

LexBFS Characterization

(LB): given an ordering of V, if a < b < c and acE and abE, then there exists a vertex d < a such that dbE

and dcE.

d a b c

LexBFS Characterization

Theorem – For an arbitrary graph G, an ordering of V is a LexBFS-ordering of G if and only if has property (LB).

The only difference between the algorithms is the requirement of dcE.

A LexBFS-ordering is a BFS-ordering, since (B) subsumes (LB).

DFS – Depth First Search

DFS explores the graph differently than BFS. It progresses forward through the graph as

much as possible, backtracking only when necessary, whereas BFS first explores close vertices before going deeper to the far more vertices.

It uses stack as its data structure to obtain this restriction.

DFS Algorithm

The data structure S is a stack. Input : a graph G = (V, E) and start vertex s Ouput : an ordering of V

1. S {s}

2. For i 1 to n do1. pop v from S

2. (i) v

3. Foreach unnumbered vertex w adjacent to v do If w is already in S then remove w to S Push w to S

DFS Characterization

(D): given an ordering of V, if a < b < c and acE and abE, then there exists a vertex a < d < b such that dbE.

da b c

DFS Characterization

Theorem – For an arbitrary graph G, an ordering of V is a DFS-ordering of G if and only if has property (D).

LexDFS – lexicographic DFS

Looking at the relation between BFS and LexBFS, one naturally asks whether there is a “lexicographic analogue” of DFS.

Forcing the restriction that dcE on the DFS characterization, immediately creates a new algorithm and a characterization for it.

LexDFS

This algorithm must act as DFS and progress forward through the graph as much as possible, but also choose its next vertex that is adjacent to as many vertices we have most recently numbered as possible.

LexDFS Characterization

(LD): given an ordering of V, if a < b < c and acE and abE, then there exists a vertex a < d < b such that dbE and dcE.

da b c

LexDFS Algorithm

Input : a graph G = (V, E) and start vertex s Ouput : an ordering of V

1. Assign the label to all vertices

2. Label(s) {0}

3. For i 1 to n do1. Pick an unnumbered vertex v with lexicographically

largest label

2. (i) v

3. Foreach unnumbered vertex w adjacent to v do Prepend i to label(w)

LexDFS Example

1

4

3

5 6

2

= {}

0

= { 1 }

1 1

= { 1 2 }

2 1

2 2

= { 1 2 3 }

33 2

= { 1 2 3 5 }

4 2 4 3

= { 1 2 3 5 6 } = { 1 2 3 5 6 4 }

LexDFS Example

1

4

3

5 6

2

= { 1 2 3 5 6 4 }

0

1 2 1

4 2 3 2 4 3

a

bc

d

Property (LD) is satisfied on the chosen triple (a,b,c)

a b cd

LexDFS Characterization

Theorem – For an arbitrary graph G, an ordering of V is a LexDFS-ordering of G if and only if has property (LD).

Difference between LexBFS and LexDFS LexBFS – we choose a vertex adjacent to as

many earliest chosen vertices as possible. LexDFS – we choose a vertex adjacent to as

many most recently chosen vertices as possible.

The two algorithms have a common restriction - dcE.

MNS – Maximal Neighborhood Search MNS is a generalization of LexBFS and

LexDFS.

Its characterization is built from the Generic Search property (S) and the restriction dcE.

Pick a vertex whose neighborhood in the part of the graph already explored is maximal.

MNS Characterization

(M): given an ordering of V, if a < b < c and acE and abE, then there exists a vertex d < b such that dbE and dcE.

a d b c

MNS Characterization

Theorem – For an arbitrary graph G, an ordering of V is a MNS-ordering of G if and only if has property (M).

MNS Algorithm

Input : a graph G = (V, E) and start vertex s Ouput : an ordering of V1. Assign the label 2. Label(s) {n+1}3. For i 1 to n do

1. Pick an unnumbered vertex v with maximal label2. (i) v3. Foreach unnumbered vertex w adjacent to v do

1. Add i to label(w)

Summary of search characterization

a

d

b c

Generic Search

LexDFS

DFS

MNS

BFS

LexBFS

dcE

dcE

dcE

d < a a < d

a < dd < a

Conclusions

The idea of characterization can be extended to more general environments.

These characterization can be applicable on multigraphs.

They give us better understanding of how a search reveals the structure of a graph

They allow us to employ multiple sweeps of a search to gather additional information about a graph.