Cycles in a directed graph - Design and Analysis - Study Notes, Study notes of Digital Systems Design

Cycles in a directed graph, Number of edges, Hamiltonian cycle, Eulerian cycle, Directed acyclic graph, Graph Representations, Adjacency matrix, Adjacency list are the key points in this study notes.

Typology: Study notes

2011/2012

Uploaded on 11/03/2012

ankitay
ankitay 🇮🇳

4.4

(50)

106 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lecture No. 28
For a digraph G = (V, E),
vv
in-degree(v) = out-degree(v) = |E|
VV∈∈
∑∑
where |E| means the cardinality of the set E, i.e., the number of edges.
For an undirected graph G = (V, E),
vdegree(v) = 2|E|
V
where |E| means the cardinality of the set E, i.e., the number of edges.
A path in directed graphs is a sequence of vertices v0, v1. . . vk such that (vi-1, vi) is an
edge for i = 1, 2, . . . , k. The length of the paths is the number of edges, k. A vertex w is
reachable from vertex u is there is a path from u to w. A path is simple if all vertices
(except possibly the fist and last) are distinct.
A cycle in a digraph is a path containing at least one edge and for which v0 = vk. A
Hamiltonian cycle is a cycle that visits every vertex in a graph exactly once. A Eulerian
cycle is a cycle that visits every edge of the graph exactly once. There are also “path”
versions in which you do not need return to the starting vertex.
Figure 8.5: Cycles in a directed graph
A graph is said to be acyclic if it contains no cycles. A graph is connected if every vertex
can reach every other vertex. A directed graph that is acyclic is called a directed acyclic
graph (DAG).
There are two ways of representing graphs: using an adjacency matrix and using an
adjacency list. Let G = (V, E) be a digraph with n = |V| and let e = |E|. We will assume
that the vertices of G are indexed {1, 2 . . . n}.
An adjacency matrix is a n × n matrix defined for 1 v, w n.
Docsity.com
pf3

Partial preview of the text

Download Cycles in a directed graph - Design and Analysis - Study Notes and more Study notes Digital Systems Design in PDF only on Docsity!

Lecture No. 28

For a digraph G = (V, E),

v v

in-degree(v) = out-degree(v) = |E|

VV

where |E| means the cardinality of the set E, i.e., the number of edges. For an undirected graph G = (V, E),

v

degree(v) = 2|E|

V

where |E| means the cardinality of the set E, i.e., the number of edges. A path in directed graphs is a sequence of vertices 〈v 0 , v 1... vk〉 such that (v i-1, vi ) is an edge for i = 1, 2,... , k. The length of the paths is the number of edges, k. A vertex w is reachable from vertex u is there is a path from u to w. A path is simple if all vertices (except possibly the fist and last) are distinct.

A cycle in a digraph is a path containing at least one edge and for which v 0 = vk. A Hamiltonian cycle is a cycle that visits every vertex in a graph exactly once. A Eulerian cycle is a cycle that visits every edge of the graph exactly once. There are also “path” versions in which you do not need return to the starting vertex.

Figure 8.5: Cycles in a directed graph

A graph is said to be acyclic if it contains no cycles. A graph is connected if every vertex can reach every other vertex. A directed graph that is acyclic is called a directed acyclic graph (DAG).

There are two ways of representing graphs: using an adjacency matrix and using an adjacency list. Let G = (V, E) be a digraph with n = |V| and let e = |E|. We will assume that the vertices of G are indexed {1, 2... n}.

An adjacency matrix is a n × n matrix defined for 1 ≤ v, w ≤ n.

An adjacency list is an array Adj[1..n] of pointers where for 1 ≤ v ≤ n, Adj[v] points to a linked list containing the vertices which are adjacent to v

Adjacency matrix requires Θ(n 2 ) storage and adjacency list requires Θ(n + e) storage.

Figure 8.6: Graph Representations

8.1 Graph Traversal To motivate our first algorithm on graphs, consider the following problem. We are given an undirected graph G = (V, E) and a source vertex s ∈ V. The length of a path in a graph is the number of edges on the path. We would like to find the shortest path from s to each other vertex in the graph. The final result will be represented in the following way. For each vertex v ∈ V, we will store d[v] which is the distance (length of the shortest path) from s to v. Note that d[s] = 0.

We will also store a predecessor (or parent) pointer π[v] which is the first vertex along the shortest path if we walk from v backwards to s. We will set π[s] = Nil.

There is a simple brute-force strategy for computing shortest paths. We could simply start enumerating all simple paths starting at s, and keep track of the shortest path arriving at each vertex. However, there can be as many as n! simple paths in a graph. To see this, consider a fully connected graph shown in Figure 8.