0% found this document useful (0 votes)
182 views3 pages

Week 4 Assignment 1

The quiz contains 5 multiple choice questions about algorithms: 1) Computing incoming edges for each vertex in an adjacency matrix representation has complexity O(n^2) 2) Replacing edge weights with paths of weight 1 edges and running BFS solves shortest paths correctly but is less efficient than Dijkstra's algorithm 3) A flight ticket price surge does not affect the cheapest routes between city pairs precomputed by TripGuru

Uploaded by

Lucky Man
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
182 views3 pages

Week 4 Assignment 1

The quiz contains 5 multiple choice questions about algorithms: 1) Computing incoming edges for each vertex in an adjacency matrix representation has complexity O(n^2) 2) Replacing edge weights with paths of weight 1 edges and running BFS solves shortest paths correctly but is less efficient than Dijkstra's algorithm 3) A flight ticket price surge does not affect the cheapest routes between city pairs precomputed by TripGuru

Uploaded by

Lucky Man
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Week 4 Quiz

.
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.

Which of the following statements is correct?

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?

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.

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?

TP must be identical to TK.


If e is a minimum cost edge in G, e belongs to both TP and TK.
If TP is different from TK, some pair of edges in G have the same weight.
If e is a maximum cost edge in G, e belongs to neither TP nor TK.

Accepted Answers:
If TP is different from TK

You might also like