Perform a depth-first search on the following graph; whenever theres a choice of vertices, pick the one that is alphabetically first. Classify each edge as a tree edge or back edge, and give the pre and post number of each vertex.
Read moreTextbook Solutions for Algorithms
Chapter 3 Problem 3.23
Question
Give an efficient algorithm that takes as input a directed acyclic graph G = (V, E), and two vertices s, \(t \in V\), and outputs the number of different directed paths from s to t in G.
Solution
Step 1 of 3
Given is a directed acyclic graph and two vertices of the graph
and
. To find the number of paths between
and
, the first step is to perform the topological sort and find the vertices that lie between
and
. The next step is to use dynamic programming to solve the problem in linear time.
Subscribe to view the
full solution
full solution
Title
Algorithms 1
Author
Sanjoy Dasgupta Algorithms, Christos H. Papadimitriou Algorithms, Umesh Vazirani Algorithms
ISBN
9780073523408