Docsity

Topological Sort and Hashing Algorithms, Slides of Data Structures and Algorithms

Toggle sidebar
bg1
Topological Sort and Hashing
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36

Partial preview of the text

Download Topological Sort and Hashing Algorithms and more Slides Data Structures and Algorithms in PDF only on Docsity!

Topological Sort and Hashing

Topological Sort

  • A topological sort of a directed graph is one in which if there is a path from v to w, v comes before w in the ordering
  • The graph must be acyclic (no cycles exist)
  • In a graph with no cycles, there must always be at least one vertex with 0 indegree, we will start at one of these vertices

The topological sorting problem: given a directed, acyclic graph G = ( V , E ) , find a linear ordering of the vertices such that for all ( v , w )  E , v precedes w in the ordering.

A

B C

F

D (^) E

The topological sorting problem: given a directed, acyclic graph G = ( V , E ) , find a linear ordering of the vertices such that for all ( v , w )  E , v precedes w in the ordering.

A

B C

F

D

A D E

E

B F C

Any linear ordering in which all the arrows go to the right.

The topological sorting problem: given a directed, acyclic graph G = ( V , E ) , find a linear ordering of the vertices such that for all ( v , w )  E , v precedes w in the ordering.

A

B C

F

D

A D F

E

B E C

Any linear ordering in which all the arrows go to the right.

This is not a topological ordering. Docsity.com

The topological sorting algorithm: Identify the subset of vertices that have no incoming edge. (In general, this subset must be nonempty—why?)

A

B C

F

D (^) E

The topological sorting algorithm: Identify the subset of vertices that have no incoming edge. (In general, this subset must be nonempty—because the graph is acyclic.)

A

B C

F

D (^) E

The topological sorting algorithm: Remove it, and its outgoing edges, and add it to the output.

A

B C

F

D (^) E

The topological sorting algorithm: Again, identify the subset of vertices that have no incoming edge,...

A

B C

F

D (^) E

The topological sorting algorithm: Again, identify the subset of vertices that have no incoming edge, select one of them, remove it and any outgoing edges, and put it in the output.

A

B C F

D (^) E

The topological sorting algorithm: Again, identify the subset of vertices that have no incoming edge, select one of them, remove it and any outgoing edges, and put it in the output.

A

B C F

D (^) E

The topological sorting algorithm: Again, identify the subset of vertices that have no incoming edge, select one of them, remove it and any outgoing edges, and put it in the output.

A B

C F

D (^) E

The topological sorting algorithm: Again, identify the subset of vertices that have no incoming edge, select one of them, remove it and any outgoing edges, and put it in the output.

A F B C

D (^) E