Suppose G is a DAG,i.e., a directed acyclic graph. Lets and t be two nodes in the graph. Describe an O(n+m) algorithm that computes the number of paths from s to t . (Hint: start by topologically ordering G.)
For example, in the illustration below, each stage of the DAG increases the total number of paths by a multiple of 3. This exponential growth can be handled with dynamic programming.

A simple modification of DFS will compute this given as
def dfs(u, t):
if u == t:
return 1
else:
if not u.npaths:
# assume sum returns 0 if u has no children
u.npaths = sum(dfs(c, t) for c in u.children)
return u.npaths
It is not difficult to see that each edge is looked at only once, hence a runtime of O(V+E).
Suppose G is a DAG,i.e., a directed acyclic graph. Lets and t be two nodes in...
You are given an unweighted DAG (Directed Acyclic Graph) G, along with a start node s and a target node t. Design a linear time (i.e., runtime O(IV+ EI)) dynamic programming algorithm for computing the number of all paths (not necessarily shortest) from s to t.
Let G be a DAG (a graph without loops) and u, v be two designated nodes (there are many other nodes in G). In particular, each node in G is labeled with a color and multiple nodes can share the same color. A good path is one where the number of green nodes is bigger than the number of yellow nodes. Describe an efficient algorithm to count the number of good paths from u to v.
Problem 1: Dynamic Programming in DAG Let G(V,E), |V| = n, be a directed acyclic graph presented in adjacency list representation, where the vertices are labelled with numbers in the set {1, . . . , n}, and where (i, j) is and edge inplies i < j. Suppose also that each vertex has a positive value vi, 1 ≤ i ≤ n. Define the value of a path as the sum of the values of the vertices belonging to...
(A) Consider the following algorithm for computing a topological sort of a DAG G: add the vertices to an initially empty list in non-decreasing order of their indegrees. Either argue that the algorithm correctly computes a topological sort of G, or provide an example on which the algorithm fails. (B) Can the number of strongly connected components of a graph decrease if a new edge is added? Why or why not? Can it increase? Why or why not? (C) What...
Suppose we are given a directed acyclic graph G with a unique source and a unique sink t. A vertex v ¢ {s,t} is called an (s,t)-cut vertex if every path from s to t passes through v, or equivalently, if deleting v makes t unreachable from s. Describe and analyze an algorithm to find every (s, t)-cut vertex in G t
Consider a directed acyclic graph G = (V, E) without edge lengths and a start vertex s E V. (Recall, the length of a path in an graph without edge lengths is given by the number of edges on that path). Someone claims that the following greedy algorithm will always find longest path in the graph G starting from s. path = [8] Ucurrent = s topologically sort the vertices V of G. forall v EV in topological order do...
Only P9.5.3 Not P9.5.1
Figure 9-7: A directed acyclic graph to be depth-first searched. P9.5.1 Let Gn be a directed acyclic graph similar to that of Figure 9-7 but with n in place of the parameter "4". Suppose that there is no goal node - how many node visits does a depth-first search take to discover this, as a function of n? P9.5.3 How many different paths of length n, starting from the start node, exist in the graph Gn...
Let G = (V, E) be a directed acyclic graph with n vertices and m edges. Give an O(n + m) time algorithm that determines if G contains a directed path that touches every vertex in G exactly once. The graph G is given by its adjacency list representation.
search take to discover this, as a function of n? P9.5.2 Suppose that a directed acyclic graph has maximum path length d and that no node has more than b neighbors. What is the largest number of node visits that could occur in a depth-first search of this graph? Show an example of such a graph that has only bd +1 nodes and has the maximum number of node visits.
search take to discover this, as a function of n?...
(Fill the blank) A Hamiltonian Path is a path in a directed graph that visits every vertex exactly once. Describe a linear time algorithm to determine whether a directed acyclic graph G=(V, E) contains a Hamiltonian path. (Hint: It might help to draw a DAG which contains a Hamiltonian path)_________.