**Question 4 (Long Paths on DAGs) [20 marks]**

Let *G* be a directed acyclic graph with *n* vertices and *m* edges.

- A Hamiltonian path in
*G*is a directed path in*G*that contains every vertex in*G*. Give an*O*(*n*+*m*) algorithm to determine whether*G*has a Hamiltonian path. - Suppose we are given an integer
*l*. Give an*O*(*n*+*m*) algorithm to find whether or not there exists a directed path with*l*or more edges in*G*.

**Question 5 (Simplified SCC Algorithm) [15 marks]**

The Kosaraju-Sharir algorithm shown in the lecture worked as follows:

- Perform DFS(
*G*) to compute finish times for all vertices - Compute
*GT* - For each vertex
*u*in*G*in reverse order of finish time

• Run DFS-Visit(*u*) in *GT* and label all vertices in its DFS tree as a separate SCC

While teaching this algorithm, Dr. Ajwani found the above algorithm to be quite confusing for students. So, he simplified the algorithm as follows:

- Perform DFS(
*G*) to compute finish times for all vertices - For each vertex
*u*in*G*in increasing order of finish time

• Run DFS-Visit(*u*) in *G* and label all vertices in its DFS tree as a separate SCC

Note that the simplified algorithm processes vertices in increasing order of finish time instead of the reverse order and performs DFS-Visit in *G* , instead of *GT* . Give a counter-example to show that the algorithm as modified by Dr. Ajwani does not produce all the strongly connected components correctly.

**Question 6 (Number of Paths) [20 marks]**

It has happened many a times that the shortest path that you took from your home to UCD was blocked because of road works and the detours were really long. So, you have decided that instead of relying on only one shortest path, you want to have many shortest paths between your home and UCD. Give an *O*(*n* + *m*) algorithm to compute how many shortest paths exists between your home and UCD. Here, *n* is the number of intersections and *m* is the number of roads between them. You can assume that all edge weights are 1.

**Welcome to one of the bestassignmenthelpcompanies online .**

**· Do you want to order for a customized assignment help task?**

**· Click on the order now button **

**· Set up your topic, Fix the number of pages, Fix your Order instructions **

**· Set up your deadline, upload the necessary files required to complete the task, Complete the payment.**

** We delivery high quality and non plagiarized tasks within the stipulated time given **

**SL**