CIS 3223. Data Structures and Algorithms

Graphs (3)

 

4. Search in a maze (continued)

Maze representation: from block-map to graph.

The notions of "shortest path" in unweighted graph and weighted graph

 

5. Topological sorting

In a directed graph G = < V, E >, a topological sorting of G "sorts" vertices in V into a sequence such that for every edge (Vi, Vj) in E, Vi appears before Vj in the sequence (though there may be other vertices between them).

In an acyclic digraph (also known as DAG), after Depth-First Search the finish order list contains the reverse of the topological sorting result. The complexity is O(|V| + |E|).

A digraph can be topologically sorted as far as there is no cycle in the graph. For a digraph that may contain cycle, a common algorithm to do topological sorting and cycle detecting is to repeatedly mark or remove vertices with no (unvisited) successor (or predecessor) from the graph. The complexity is O(|V|2) when an adjacent matrix is used to implement the graph.