## NPTEL Design and Analysis of Algorithms Week 4 Assignment Answers 2024

1. We are given a directed graph, represented as an adjacency list, in which each vertex has at least one incoming edge and one outgoing edge. We would like to print out for each vertex j the list of vertices pointing into j. What is the most accurate description of the complexity of computing these quantities in terms of n, the number of vertices, and m, the number of edges?

- O(n
^{2}) - O(nm)
- O(m)
- O(n)

Answer :-For Answer Click Here

2. Which of the following would compute shortest paths in a weighted graph without negative weights?

- BFS using a stack instead of a regular queue.
- BFS using a priority queue instead of a regular queue.
- DFS using a priority queue instead of a stack.
- DFS using a priority queue instead of a stack.

Answer :-For Answer Click Here

3. Consider the following algorithm on a graph with edge weights.

Sort the edges as [e_{1},e_{2},…,e_{m}] in decreasing order of cost.

Start with the original graph. Consider each edge ej. If this edge is part of a cycle delete it.

Which of the following is not true.

- At most n-1 edges will be deleted.
- After processing all m edges, the resulting graph is connected.
- What remains at the end is a minimum cost spanning tree.
- Exactly m-n+1 edges will be deleted.

Answer :-For Answer Click Here

4. How can we use the Bellman-Ford algorithm to detect negative cycles in a weighted graph with n vertices?

- Check if the shortest path between some pair of vertices is negative.
- Check if the distance between some pair of vertices decreases after any iteration.
- Check if the distance between some pair of vertices decreases after the nth iteration.
- The Bellman-Ford algorithm cannot be used to detect negative cycles.

Answer :-

5. Suppose we run Prim’s algorithm and Kruskal’s algorithm on a graph G and the two algorithms produce minimum-cost spanning trees T_{P} and T_{K}. Which of the following is true?

- T
_{P}must be identical to T_{K}. - If T
_{P}is identical to T_{K}, all edges in G have distinct weights. - T
_{P}and T_{K}can differ in at most one edge. - If T
_{P}is different from T_{K}, some pair of edges in G have the same weight.

Answer :-For Answer Click Here