Tải bản đầy đủ (.pptx) (31 trang)

Thuyết trình môn giải thuật nâng cao nhóm 4 coursework

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (324.62 KB, 31 trang )

Strongly Connected
Components
Tarjan's strongly connected components algorithm
13070274 – Nguyễn Anh Tuấn
13070262 – Lê Nguyễn Hoàng Thanh
13070244 – Nguyễn Thị Thuý Loan
13070242 – Trần Thạch Lam


Outline
1.

Strongly connected component?

2.

Tarjan’s strongly connected components algorithm

3.

Applications

4.

Demonstration


Outline
1.

Strongly connected component?



2.

Tarjan’s strongly connected components algorithm

3.

Applications

4.

Demonstration


Strongly connected component?
 A strongly connected component of a

directed graph G is a maximal set of
vertices C V such that for every pair of
vertices u and v, there is a directed path
from u to v and a directed path from v to
u.

Each vertex v is connected to itself.
This relation partitions V into disjoint sets
that we call strongly connected
components.


Strongly connected component?

Some algorithms to compute strongly connected component

Kosaraju’s two-pass algorithm, is named after S. Rao Kosaraju, who described it, and
then Micha Sharir later published it.

Tarjan’s algorithm, published by Robert Tarjan in 1972.
The path-based strong component algorithm uses a depth first search, like Tarjan’s
algorithm, but with two stack.


Outline
1.

Strongly connected component?

2.

Tarjan’s strongly connected components algorithm

3.

Applications

4.

Demonstration


Tarjan’s algorithm
The basic idea


The Tarjan’s algorithm is based on depth
first search (DFS)

The vertices are indexed as they are
traversed by DFS procedure

Every vertex V gets assigned a vertex L as
a representative while returning from the
recursion of DFS


Tarjan’s algorithm
The basic idea (cont.)

L is a vertex with the least index (low link)
that can be reach from V

Nodes with the same representative
assigned are located in the same strongly
connected component.


Tarjan’s algorithm
Roots of components
Components of the graph are just subtrees of the DFS tree
To find components, we just have to break tree at certain edges
A vertex is a “root” of a component if it’s the topmost
The crucial has turned into determining whether a given vertex v is root
How?

A vertex is a root by looking for the existence of back or cross edges out of its subtree.


Tarjan’s algorithm - Pseudocode


Tarjan’s algorithm - Pseudocode


Tarjan’s algorithm - Example


Tarjan’s algorithm - Example
Begin from A
A.index = 1
A.lowlink = 1
Push A into stack

Stack = {A}
SSC = {}
For all descendants of A {B, G}


Tarjan’s algorithm - Example
At node B
B.index = 2
B.lowlink = 2
Push B into stack

Stack = {B, A}

SSC = {}
For all descendants of B {C}


Tarjan’s algorithm - Example
At node C
C.index = 2
C.lowlink = 2
Push C into stack

Stack = {C, B, A}
SSC = {}
For all descendants of C {D}


Tarjan’s algorithm - Example
At node D
D.index = 2
D.lowlink = 2
Push D into stack

Stack = {D, C, B, A}
SSC = {}
For all descendants of D {E}


Tarjan’s algorithm - Example
At node E
E.index = 2
E.lowlink = 2

Push E into stack

Stack = {E, D, C, B, A}
SSC = {}
For all descendants of E {F}


Tarjan’s algorithm - Example
At node E
E.index = 2
E.lowlink = 2
Push E into stack

Stack = {E, D, C, B, A}
SSC = {}
For all descendants of E {F}


Tarjan’s algorithm - Example
At node F
F.index = 2
F.lowlink = 2
Push F into stack

Stack = {F, E, D, C, B, A}
SSC = {}
For all descendants of F {C}


Tarjan’s algorithm - Example

At node C exist in stack
Update parent node F of C
F.lowlink = 3

Update parent node E of F
E.lowlink = 3

Update parent node D of E
D.lowlink = 3

Update parent node C of D
C.lowlink = 3


Tarjan’s algorithm - Example
At node C lowlink = index
Pop {F, E, D, C} out of stack
Stack = {B, A}
SSC = {{F, E, D, C}}
At node B lowlink = index
Pop {B} from stack
Stack = {A}
SSC = {{F, E, D, C}, {B}}


Tarjan’s algorithm - Example
At node G
G.index = 7
G.lowlink = 7
Push G into stack


Stack = {G, A}
SSC = {{F, E, D, C}, {B}}
For all descendants of G {B, H}


Tarjan’s algorithm - Example
At node B doesn’t exist in stack
Do nothing

Stack = {G, A}
SSC = {{F, E, D, C}, {B}}


Tarjan’s algorithm - Example
At node H
H.index = 8
H.lowlink = 8
Push H into stack

Stack = {H, G, A}
SSC = {{F, E, D, C}, {B}}
For all descendants of G {}


Tarjan’s algorithm - Example
At node H lowlink = index
Pop {H}, Stack = {G, A}
SSC = {{F, E, D, C}, {B}, {H}}
At node G lowlink = index

Pop {G}, Stack = {A}
SSC = {{F, E, D, C}, {B}, {H}, {G}}
At node A lowlink = index
Pop {A}, Stack = {}
SSC = {{F, E, D, C}, {B}, {H}, {G}, {A}}


×