



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Week 15 ______________________________________________________________________________
Reading:
Objectives:
Concepts:
Outline:
Reference:
Graphs:
a) G(V,E) — V : vertex set; E: edge set. b) Directed graphs, undirected graphs, weighted graphs. c) A path from a vertex v to vertex v’ is a sequence of vertices (v 0 , v 1 , …., vk) such that v = v 0 , v’ = vk , and (vi-1, vi) belongs to E for i = 1, 2, ….., k. d) Length of path: either the number of edges in the path or the total weight. e) Simple path: all vertices in the path are distinct. f) Cyclic graph: graph that consist of a cycle. g) Acyclic graph: graph that contains no cycle. h) Graph Representation:
Breadth First Search
a) Definition: i. Simplest graph search algorithm ii. Begins at the root node and explores all the neighboring nodes iii. For those nearest nodes, it explores their unexplored neighbor nodes and so on until it finds a goal.
b) Basic Strategy:
i. Mark the current vertex v as “discovered” ii. For each edge (v, w) in graph G with “undiscovered” successor w
c) Properties of BFS
i. Vertices are visited in order of increasing distance from the start vertex
CS 331: Week 15 - Lecture Notes
a) Definition: i. A topological sort of Directed Acyclic Graph (DAG) is a linear ordering of all its vertices such that,
b) Algorithm:
i. Use DFS(G) to compute finishing time f(v) for each vertex v ii. As each vertex is finished, insert it into the front of the linked list iii. Return the linked list of vertices.
c) Properties
i. Insertion into the linked list cost Ө (1) for each |V| insertions. ii. The time cost of topological sort is only Ө(|V| + |E|)
d) Application:
i. Decomposing a directed graph into its strongly connected components.
a) Definition:
i. A digraph is called strongly connected if for every pair of vertices u and v , there is a path from u to v and a path from v to u. ii. The Strongly Connected Components (SSC) of a digraph are its maximal strongly connected subgraphs. iii. If each strongly connected component is contracted to a single vertex, the resulting graph is a directed acyclic graph.
b) Algorithm:
i. Perform DFS(G) to compute finishing time f(u) for each vertex u ii. Compute transposed graph GT iii. Perform DFS(GT), but in the main loop of DFS, consider the vertices in order of decreasing f[u] iv. Produce as output the vertices of each tree in the DFS forest as a separate SCC.
c) Properties:
i. G and GT^ have exactly the same strongly connected components. ii. Time complexity is Ө(|V| + |E|):
a) Implementing BFS algorithm and analyzing its time complexity. b) Implementing DFS algorithm and analyzing its time complexity. c) Implementing Topological Sort to compute Strongly Connected Components.