Download presentation
Presentation is loading. Please wait.
1
Chapter 3. Decompositions of Graphs
Computer Algorithms Chapter 3. Decompositions of Graphs Some of contents in this lecture slides are from textbook Sanjoy Dasgupta, Christos Papdimitriou and Umesh Vazirani, Algorithms, McGraw-Hill, 2008.
2
What is Graph? A graph is ordered pair G = (V, E) comprising a set V of vertices or nodes together with a set E of edges or lines, which connect 2 vertices. Size of Graph: the number of edges in a graph, represented by |E|. Order of Graph: the number of vertices in a graph. Degree of a vertex: the edges that a vertex has. Adjacency: if two vertices shares same edge, then we call they are adjacent.
3
Why Graphs? To solve a problem, we need to simplify and abstract the problem and target domain. Using graphs are good methodology to represent and simplify real problems. Country border relationship Which countries share their borders? Course scheduling problem To find overlapping courses
5
Graph Representation Adjacency Matrix Adjacent List
n vertices with n × n array whose (i,j)th entry is Total space for n-vertex sized graphs requires n2. Can be sparse and waste memory. Adjacent List Save space as total space requires will be O(|V|+|E|)
6
Graph Representation Adjacent Matrix 1 2 3 Adjacent List 1 2 3 2 1 3 1
7
Exploring Maze Similar to graph navigation
8
Graph Reachability Check
The most popular graph problem What part of the graphs are reachable from a given vertex?
10
Depth First Search Starting from a vertex, repeatedly do explore() until all vertices are visited. O(|V|+|E|) Pre/PostVisit Ordering Numbering Visiting Orders
11
pre post pre/post numbers are assigned based on the visiting orders.
Search does not extend to visited vertices (which already have pre numbers).
12
Depth First Search Starting a vertex, conduct explore()
During explore(), mark the vertex with pre/post visit number. Scan adjacent edges and move to the unvisited vertex to continue explore() recursively. If there is no vertex to continue then return to the previous vertex.
13
Depth First Search in Directed Graph
Directed Graph: A graph with directed edges (arrows)
14
Type of Edges in DFS search
pre/post ordering for edge types
15
Directed Acyclic Graphs (DAG)
cycle Acyclic Graph: a graph without any cycle. Property 1 A directed Graph has a cycle if and only if its depth- first search reveals a back edge. Property 2 In dag, every edge leads to a vertex with a lower post number. Property 3 Every dag has at least one source and at least one sink
16
Strongly Connected Components (SCC)
Definition of “connected” Two nodes u,v are connected if there is a path from u to v and a path from v to u. The “connected” property partitions a graph into several strongly connected components.
17
Algorithms for making SCC
SCC Properties to consider If the explore subroutine is started at node u, then it will terminate precisely when all nodes reachable from u have been visited. The node that receives the highest post number in a depth-first search must lie in a source SCC. If C and C’ are SCC and there is an edge from C to C’, then highest post number in C’ is bigger than that of C’’.
18
Algorithms for making SCC
Run depth-first search on G. Vertices on G will have pre/post numbers Run depth-first search on GR (reverse graph of G)from the highest post numbered vertex. If we cannot extend further on GR, then remove vertices as SCC, and start another remaining vertex with highest post number.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.