Home / Expert Answers / Computer Science / 4-counting-simple-paths-in-a-dag-45-pts-in-this-problem-you-will-design-an-algorithm-that-takes-pa642

(Solved): 4 Counting Simple Paths in a DAG (45 pts) In this problem you will design an algorithm that takes ...



4 Counting Simple Paths in a DAG (45 pts)
In this problem you will design an algorithm that takes as input a directed acyclic

4 Counting Simple Paths in a DAG (45 pts) In this problem you will design an algorithm that takes as input a directed acyclic graph and two vertices and , and returns the number of simple paths from to in . For example, the directed acyclic graph below contains exactly four simple paths from vertex to vertex : pov, poryv, posryv, and psryv. Notice: your algorithm needs only to count the simple paths, not list them. (a) (15 pts) Design a recursive backtracking (brute-force) algorithm that determines the number of paths from to . Write down the pseudocode of your algorithm and prove its correctness, i.e., convince us that it works beyond any doubt. (Hint: using induction.) A solution with no proof will receive 0 points! Make your pseudocode as simple as possible. You will be graded on the elegance of your solution, not just the correctness. (b) (15 pts) Modify your pseudocode in part (a) to use memoization. Write down the modified pseudocode and explain your choice of the memoization table and the indices used for memoization. (Hint: What is a natural way to memoize solutions to subproblems that had already been computed?) (c) (15 pts) Design a bottom-up dynamic programming algorithm that counts the number of simple paths from to . Write the pseudocode and analyze its running time. Argue why your choice of the order in which you fill in the values is the correct one. (Hint: Think about the order on which the computation of the paths from each vertex depends.)


We have an Answer from Expert

View Expert Answer

Expert Answer


Answer :- (a) Recursive backtracking algorithm:countPaths(s, t): if s == t: return 1 count = 0 for each neighbor v of s: count
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe