Sunteți pe pagina 1din 32

Theoretical Foundations of

Computer Science
(Graphs)
J.J. ADRI JOVIN
Assistant Professor (Sr. Gr.)/IT

4/22/17 1
Network Flow Problems

4/22/17 2
Real-time Applications
Water Flow through a pipe
Amount of traffic that can flow on a street between two
intersections

4/22/17 3
Graph and its Maximum flow

s s
3 2 3 2
1 0
a b a b

3 2 2 2
4 1

c d c d
2 3 2 3

t t
4/22/17 4
Initial Stage
s s s
3 2 0 0 3 2
1 0 1
a b a b a b

3 2 0 0 3 2
4 0 4

c d c d c d
2 3 0 0 2 3

t t t

4/22/17 5
Graph Flow Graph Residual Graph
After 2 units of flow added along s,b,d,t
s s s
3 2 0 2 3
1 0 1
a b a b a b

3 2 0 2 3
4 0 4

c d c d c d
2 3 0 2 2 1

t t t

4/22/17 6
Graph Flow Graph Residual Graph
After 2 units of flow added along s,a,c,t
s s s
3 2 2 2 1
1 0 1
a b a b a b

3 2 2 2 1
4 0 4

c d c d c d
2 3 2 2 1

t t t

4/22/17 7
Graph Flow Graph Residual Graph
After 1 units of flow added along s,a,d,t
algorithm terminates
s s s
3 2 2 2
1 0 1
a b a b a b

3 2 2 2 1
4 1 3

c d c d c d
2 3 2 3

t t t

4/22/17 8
Graph Flow Graph Residual Graph
If 3 units of flow along s,a,d,t
Sub-optimal Solution
s s s
3 2 3 0 2
1 0 1
a b a b a b

3 2 0 0 3 2
4 3 1

c d c d c d
2 3 0 3 2

t t t

4/22/17 9
Graph Flow Graph Residual Graph
3 units flow added along s,a,d,t using
correct algorithm
s s s
3 2 3 0 3 2
1 0 1
a b a b a b

2 0 0 3 2
3 3
4 3 1

c d c d c d
2 3 0 3 2 3

t t t

4/22/17 10
Graph Flow Graph Residual Graph
2 units flow added along s,b,d,a,c,t using
correct algorithm
s s s
3 2 3 2 3 2
1 0 1
a b a b a b

2 2 0 2 1 2
3
4 1 1 3

c d c d c d
2 3 2 3 2 3

t t t

4/22/17 11
Graph Flow Graph Residual Graph
Spanning Trees
Prims Algorithm

Kruskals Algorithm

Real-time Applications
Wiring

GPS Navigation
4/22/17 12
Minimum Spanning Tree
2 2
v1 v2 v1 v2
4 1 3 10 1

2 7 2
v3 v4 v5 v3 v4 v5
8 4 4
6 6
5 1 1
v6 v7 v6 v7

4/22/17 13
Prims Algorithm

4/22/17 14
Initial Configuration
V Known Dv Pv
v1 v2
V1 0 0 0

v3 v4 v5 V2 0 0



V3 0 0


v6 v7
V4 0 0

V5 0 0

V6 0 0

v7 0 0

4/22/17 15
After v1 is declared known
V Known Dv Pv
v1 v2
1 V1 1 0 0

v3 v4 v5 V2 0 2 V1

V3 0 4 V1

v6 v7 V4 0 1 V1

V5 0 0

V6 0 0

v7 0 0

4/22/17 16
After v4 is declared known
2 V Known Dv Pv
v1 v2
1 V1 1 0 0

v3 v4 v5 V2 0 2 V1

V3 0 4 V14

v6 v7 V4 1 1 V1

V5 0 7 V4

V6 0 8 V4

v7 0 4 V4

4/22/17 17
After v2 and v3 are declared known
2
v1 v2
1
V Known Dv Pv
2
v3 v4 v5
V1 1 0 0

V2 1 2 V1
v6 v7
V3 1 2 V14

2 V4 1 1 V1
v1 v2
1 V5 0 7 V4
2
v3 v4 v5 V6 0 5 V3
4
v7 0 4 V4
v6 v7
4/22/17 18
After v7 is declared known
2 V Known Dv Pv
v1 v2
1 V1 1 0 0

2
v3 v4 v5 V2 1 2 V1

4
V3 1 2 V14
1
v6 v7 V4 1 1 V1

V5 0 6 V7

V6 0 1 V7

v7 1 4 V4

4/22/17 19
After v6 and v5 are selected
2 V Known Dv Pv
v1 v2
1 V1 1 0 0

2
v3 v4 v5 V2 1 2 V1

4
V3 1 2 V14
6
1
v6 v7 V4 1 1 V1

V5 1 6 V7

V6 1 1 V7

v7 1 4 V4

4/22/17 20
Kruskals Algorithm
v1 v2 v1 v2
1

v3 v4 v5 v3 v4 v5

v6 v7 v6 v7

v1 v2
1

v3 v4 v5

1
4/22/17 v6 v7 21
Kruskals Algorithm (Contd..)
2 2
v1 v2 v1 v2
1 1

2
v3 v4 v5 v3 v4 v5

1
v6 v7 v6 v7
2
v1 v2
1

2
v3 v4 v5
4
1
4/22/17 v6 v7 22
Kruskals Algorithm(Contd..)

2
v1 v2
1

2
v3 v4 v5
4
6
1
v6 v7

4/22/17 23
NP-Complete Problems in Graphs
K-Clique

Vertex Cover

Independent Set

4/22/17 24
Cliques
K-clique = complete subgraph of k nodes and are pair-wise adjacent

a d f

b e g

4/22/17 25
Real-time Applications
Social Networks

Computing Protein Similarity

Finding Error Correcting Codes

4/22/17 26
K-Cliques
A K-clique is a set of K nodes with all K(K-1)/2 possible
edges between them

This graph contains a 4-clique

4/22/17 27
Independent Set
An independent set is a set of nodes with no edges
between them

This graph contains an independent set of size 3

4/22/17 28
Independent Set
Given a graph G and k, is there a size k independent
set?

4/22/17 29
Vertex Cover
vertex cover = set of nodes that cover all edges

a d
a d

c c

b e

b e

4/22/17 30
Vertex Cover is NP Complete
Given a Graph G(V,E), decide if there is k vertex such
that every edge is covered by one of them?

4/22/17 31
References
Data Structures and Algorithms, 2nd Ed., Mark Allen Weiss
Data Structures, Seymour Lipschutz
Data Structures with C++, John R. Hubbard
Formal Languages, Automata, and Computation (FLAC),
http://www.cs.cmu.edu/~emc/flac09/lectures/ by Edmund M.
Clarke

4/22/17 32

S-ar putea să vă placă și