Week 4 Assignment 1
Week 4 Assignment 1
.
Submitted assignment
All questions carry equal weightage. You may submit as many times as you like within the deadline.
Your final submission will be graded.
1) We are given a directed graph, using an adjacency matrix representation. For each vertex v,2 points
we want to compute the set of incoming edges (u, v). Which of the following is the most accurate
description of the complexity of this computation. (Recall that n is the number of vertices and m is the
number of edges.)
O(n)
O(n+m)
O(n2)
O(m)
Accepted Answers:
O(n2)
2) Consider the following strategy to solve the single source shortest path problem with edge 2 points
weights from source s.
1. Replace each edge with weight w by w edges of weight 1 connected by new intermediate nodes.
2. Run BFS(s) on the modified graph to find the shortest path to each of the original vertices in the
graph.
This strategy will solve the problem correctly but is not as efficient as Dijkstra's algorithm.
This strategy will solve the problem correctly and is as efficient as Dijkstra's algorithm.
This strategy will not solve the problem correctly.
Accepted Answers:
This strategy will solve the problem correctly but is not as efficient as Dijkstra's algorithm.
3) An airline charges a fixed price for each direct flight. For each sequence of hopping flights, 2 points
the ticket price is the sum of the fares of the individual sectors. TripGuru has precalculated the cheapest
routes between all pairs of cities so that it can offer an optimum choice instantly to customers visiting its
website. Overnight, the government has added a 13% luxury service surcharge to the cost of each
https://onlinecourses.nptel.ac.in/noc17_cs27/unit?unit=151&assessment=152 1/3
Design and analysis of algorithms - - Unit 12 - W
There is no impact. Cheapest routes between all pairs of cities remains unchanged.
The surcharge favours hopping flights with fewer sectors. TripGuru should recompute any
cheapest route where there is a shorter route in terms of number of flights.
The surcharge favours hopping flights with more sectors. TripGuru should recompute any
cheapest route where there is a longer route in terms of number of flights.
The impact is unpredictable. TripGuru should recompute all cheapest routes.
Accepted Answers:
There is no impact. Cheapest routes between all pairs of cities remains unchanged.
4) How can we use the Bellman-Ford algorithm to detect negative cycles in a weighted graph 2 points
with n vertices?
Accepted Answers:
Check if the distance between some pair of vertices decreases after the nth iteration.
5) Suppose we run Prim’s algorithm and Kruskal’s algorithm on a graph G and the two 2 points
algorithms produce minimum-cost spanning trees TP and TK, respectively. Which of the following is true?
Accepted Answers:
If TP is different from TK