Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
60% found this document useful (5 votes)
11K views

NPTEL Design and Analysis of Algorithm

All assignments answers of NPTEL DAA

Uploaded by

iraj shaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
60% found this document useful (5 votes)
11K views

NPTEL Design and Analysis of Algorithm

All assignments answers of NPTEL DAA

Uploaded by

iraj shaikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Design and analysis of algorithms - - Unit 5 - We... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

reviewer3@nptel.iitm.ac.in ▼

Courses » Design and analysis of algorithms

Announcements Course Ask a Question Progress Mentor FAQ

Unit 5 - Week
1 Quiz

Course
outline
Week 1 Quiz
The due date for submitting this assignment has passed.
How to access As per our records you have not submitted this Due on 2018-09-12, 23:59 IST.
the portal assignment.

Week 1: All questions carry equal weightage. You may submit as many times as you like within the deadline.
Introduction Your final submission will be graded.

Week 1: 1) In the code fragment below, start and end are integer values and gcd(x,y) is a 2 points
Analysis of function that computes the greatest common divisor of x and y.
algorithms

Week 1 Quiz i := 0; j := 0; k := 0;
for (m := start; m <= end; m := m+1){
Quiz : Week 1 if (gcd(m,9381) > 2){
Quiz
i := i + m;
Week 2: k := k + m;
Searching and }else{
sorting j := j + m;
k := k + m;
Week 2 Quiz }
}
Week 2
Programming At the end of the loop which of the following expresses a valid relation between i, j and k?
Assignment
k == i - j
Week 3: Graphs
k == j - i
Week 3 Quiz
k == i + j

Week 3 The relationship depends on start and end


Programming
Assignment No, the answer is incorrect.
Score: 0
Week 4: Feedback:
Weighted graphs n each iteration, one of i or j increases and k increases by the same amount, so i + j = k is an invarant.
Accepted Answers:
Week 4 Quiz

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

1 of 3 Friday 09 November 2018 01:10 PM


Design and analysis of algorithms - - Unit 5 - We... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

Union-Find and ans := ans by


Powered * 2
Heaps m := m - n
}
Week 5: Divide
return(ans)
and Conquer
}

Week 5 Quiz

Week 6: Data
Structures: No, the answer is incorrect.
Search Trees Score: 0
Feedback:
Week 6: Greedy Repeatedly subtracting n is the same as dividing by n, so the number of iterations is equal to the quotient of
Algorithms
m/n (i.e. the integer part of m/n).

Week 6 Quiz Accepted Answers:


(Type: Numeric) 12
Week 7:
2 points
Dynamic
Programming 3) Let f(n) = 16n3 +10 n log n and g(n) = 8758 n2 log n + 9248 n2. Which of the following is 2 points
true?
Week 7 Quiz
f(n) is O(g(n)) and g(n) is O(f(n)).
Week 7
Programming g(n) is O(f(n)), but f(n) is not O(g(n))
Assignment
f(n) is O(g(n)), but g(n) is not O(f(n))
Week 8: Linear f(n) is not O(g(n)) and g(n) is not O(f(n))
Programming
and Network No, the answer is incorrect.
Flows Score: 0
Feedback:
Week 8:
Intractability f(n) is O(n3), g(n) is O(n2 log n), so g(n) is O(f(n)) but not vice versa.
Accepted Answers:
Week 8 Quiz g(n) is O(f(n)), but f(n) is not O(g(n))

TEXT 4) Suppose T(n) = n √ n. Consider the following statements. 2 points


TRANSLATION
(A) T(n) is O(n3)
(B) T(n) is O(n log n)

Both (A) and (B) are correct.

(A) is correct, but (B) is not.

(B) is correct, but (A) is not

Neither (A) nor (B) is correct.

No, the answer is incorrect.


Score: 0
Feedback:
√n is not O(log n), so n √ n is not O(n log n). O(n2) is a tighter bound than O(n3), but the weaker bound is
also correct.
Accepted Answers:
(A) is correct, but (B) is not.

5) A new algorithm MaxPack for optimally packing furniture in a transportation container 2 points
claims to have worst case complexity O(n2 log n), where n is the number of items to be packed.
From this, we can conclude that:

For every sufficiently large n, for every input of size n, MaxPack requires time proportional to
n2 log n.

For some n, for every input of size n, MaxPack requires time proportional to n2 log n.

2 of 3 Friday 09 November 2018 01:10 PM


Design and analysis of algorithms - - Unit 5 - We... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

For every sufficiently large n, every input of size n can be solved by MaxPack within time
proportional to n2 log n.

For every sufficiently large n, there is an input of size n for which MaxPack requires time
proportional to n2 log n.

No, the answer is incorrect.


Score: 0
Feedback:
O() only provides an upper bound for all inputs. It does not imply that any input requires that much time
(which would be a lower bound).
Accepted Answers:
For every sufficiently large n, every input of size n can be solved by MaxPack within time proportional to n
log n.

End

3 of 3 Friday 09 November 2018 01:10 PM


18/07/2018 Design And Analysis Of Algorithms - - Unit 6 - Week 2 Quiz

reviewer1@nptel.iitm.ac.in ▼

Courses » Design And Analysis Of Algorithms

Announcements Course Ask a Question Progress Mentor

Unit 6 - Week 2
Quiz

Course
outline Week 2 Quiz
The due date for submitting this assignment has passed. Due on 2018-02-21, 23:59 IST.
How to access
the portal Submitted assignment

Week 1: All questions carry equal weightage. You may submit as many times as you like within the deadline.
Introduction Your final submission will be graded.

1) An array A contains N integers arranged in a random sequence. We want to check if any 2 points
Week 1: Analysis
of algorithms value is duplicated in the sequence. Which of the following would be the most efficient algorithm,
asymptotically.
Week 1 Quiz
For each pair of positions i and j, check if A[i] is equal to A[j].

Week 2: Sort the array using insertion sort. When inserting each element into the sorted prefix, check if
Searching and there is already a value equal to it in the prefix.
sorting Sort the array using merge sort. Scan the sorted array from beginning to end looking for
adjacent equal elements.
Week 2 Quiz
Sort the array using quick sort. Use binary search on the sorted array to find duplicated values.
Quiz : Week 2 No, the answer is incorrect.
Quiz
Score: 0
Week 2 Quiz Feedback:
Solution
Sorting in O(n log n) and doing a linear scan is asymptotically O(n log n). Comparing all pairs of indices is
Week 2 O(n2), as is using insertion sort to do the identification or using quicksort. Also, for the last option it is not
Programming clear why binary search is useful.
Assignment
Accepted Answers:
Week 3: Graphs Sort the array using merge sort. Scan the sorted array from beginning to end looking for adjacent equal
elements.
Week 3 Quiz 2) A CPU can perform 108 operations a second. You are implementing an O(n2 log n) 2 points
2

Week 3 algorithm to solve a problem. You want to demonstrate the algorithm to your boss, and ensure that the
Programming program runs within 1 second on all the demos. Among the following values of n, which is the largest
Assignment safe value for the demo?

Week 4: n = 7500
Weighted graphs n = 5000
n = 2000
Week 4 Quiz
n = 1000
Week 4 No, the answer is incorrect.
Programming
Score: 0
Assignment
Feedback:
Week 5: Data 50002 is 2.5×107 and log 5000 is between 12 and 13, so worst case for n = 5000 can cross 3×108.
Structures:
Union-Find and Accepted Answers:
Heaps n = 2000
https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=123&assessment=124 1/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 6 - Week 2 Quiz
3) Assume that a CPU can process 108 operations per second. Suppose you have to sort an 0 points
Week 5: Divide
and Conquer array with 106 elements. Which of the following is true?

Selection sort will always take more than 2.5 hours while merge sort will always take less than 1
Week 5 Quiz
second.
Week 6: Data Insertion sort will always take more than 2.5 hours while quicksort will always take less than 1
Structures: second
Search Trees Insertion sort could take more than 2.5 hours while merge sort will always take less than 1
second.
Week 6: Greedy
Algorithms Selection sort could take more than 2.5 hours while quicksort will always take less than 1
second.
Week 6 Quiz No, the answer is incorrect.
Score: 0
Week 6
Programming Feedback:
Assignment Selection sort, insertion sort and quick sort all have worst case complexity O(n2). Only merge sort has
complexity O(n log n). Algorithms with worst case O(n2) could take more than 2.5 hours, but will not alway
Week 7: Dynamic
Programming do so. Worst case O(n log n) will always take less than 1 second. So the correct answer is that insertion
sort may take over 2.5 hours, while merge sort will not take more than 1 second.
Week 7 Quiz Accepted Answers:
Insertion sort could take more than 2.5 hours while merge sort will always take less than 1 second.
Week 7
Programming 4) Suppose our aim is to sort an array in ascending order. Which of the following statements is 2 points
Assignment true?

Week 8: Linear Input in ascending order is worst case for both selection sort and insertion sort.
Programming Input in descending order is worst case for both selection sort and insertion sort.
and Network
Input in ascending order is worst case for insertion sort but not for selection sort.
Flows
Input in descending order is worst case for selection sort but not for insertion sort.
Week 8:
No, the answer is incorrect.
Intractability
Score: 0
Week 8 Quiz Feedback:
Input in descending order and ascending order are both worst case for selection sort. Input in descending
Download order is worst case for insertion sort.
Accepted Answers:
TEXT Input in descending order is worst case for both selection sort and insertion sort.
TRANSLATION
5) We have a list of pairs [("Tariq",71),("Brinda",85),("Shweta",71),("Sunita",85),("Salma",72), 2 points
("Uday",60)], where each pair consists of a student's name and his/her marks in a course. We sort these
pairs in ascending order of marks. Which of the folllowing corresponds to a stable sort of this input?

[("Uday",60),("Tariq",71),("Shweta",71),("Salma",72),("Brinda",85),("Sunita",85)]
[("Brinda",85),("Salma",72),("Shweta",71),("Sunita",85)("Tariq",71),("Uday",60)]
[("Uday",60),("Shweta",71),("Tariq",71),("Salma",72),("Brinda",85),("Sunita",85)]
[("Uday",60),("Tariq",71),("Shweta",71),("Salma",72),("Sunita",85),("Brinda",85)]

No, the answer is incorrect.


Score: 0
Feedback:
Stable sort preserves original order when marks are same. Therefore ("Tariq",71) should be before
("Shweta",71) and ("Brinda",85) should be before ("Sunita",85).
Accepted Answers:
[("Uday",60),("Tariq",71),("Shweta",71),("Salma",72),("Brinda",85),("Sunita",85)]

Previous Page End

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=123&assessment=124 2/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 6 - Week 2 Quiz

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

Powered by

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=123&assessment=124 3/3
Design and analysis of algorithms - - Unit 10 - ... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

reviewer3@nptel.iitm.ac.in ▼

Courses » Design and analysis of algorithms

Announcements Course Ask a Question Progress Mentor FAQ

Unit 10 - Week
3 Quiz

Course
outline
Week 3 Quiz
The due date for submitting this assignment has passed.
How to access As per our records you have not submitted this Due on 2018-09-19, 23:59 IST.
the portal assignment.

Week 1: All questions carry equal weightage. You may submit as many times as you like within the deadline.
Introduction Your final submission will be graded.

Week 1: 1) Which of the following statements is not true about breadth-first search (BFS) in an 2 points
Analysis of undirected graph starting at a vertex v?
algorithms
BFS identifies all vertices reachable from v.
Week 1 Quiz
Using an adjacency list instead of an adjacency matrix can improves the worst case
Week 2: complexity to O(n + m).
Searching and BFS cannot be used to check for cycles in the graph.
sorting
BFS can be used to identify the furthest vertex from v in any graph, in terms of number of
Week 2 Quiz edges.

No, the answer is incorrect.


Week 2
Programming Score: 0
Assignment Feedback:
If we compute the BFS tree, any non tree edge indicates a cycle.
Week 3: Graphs
Accepted Answers:
Week 3 Quiz BFS cannot be used to check for cycles in the graph.

2) An airline serves 200 cities and runs 1100 direct flights each day between these cities. 2 points
Quiz : Week 3
Quiz Which of the following is a good data structure to represent the collection of flights?

Week 3 A 200 × 200 array A, where A[i][j] = 1 if there is a direct flight from city i to city j and 0
Programming otherwise.
Assignment
A stack containing values (i, j) for each pair of cities i, j for which there is a direct flight from
Week 4: city i to city j.
Weighted graphs
A queue containing values (i,j) for each pair of cities i, j for which there is a direct flight from
Week 4 Quiz city i to city j.

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

1 of 3 Friday 09 November 2018 01:13 PM


Design and analysis of algorithms - - Unit 10 - ... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

Union-Find and the adjacency matrix has


Powered by 200 × 200 = 40000 entries while the adjacenty list has 2 × 1100 = 2200 entries.
Heaps
Accepted Answers:
A list containing values (i, j) for each pair of cities i, j for which there is a direct flight from city i to city j.
Week 5: Divide
and Conquer 3) How many topological orderings does the following directed acyclic graph have? 2 points

Week 5 Quiz

Week 6: Data
Structures:
Search Trees

Week 6: Greedy 4
Algorithms
12

Week 6 Quiz 18

24
Week 7:
Dynamic
No, the answer is incorrect.
Programming
Score: 0

Week 7 Quiz Feedback:


Any toplogical ordering has to put {2,3,4,5} between 1 and 6 and {7,8,9} between 6 and 10. There are 6
Week 7 valid ways to order {2,3,4,5} and 3 ways to ordre {7,8,9}, so the total is 6 × 3 = 18.
Programming
Accepted Answers:
Assignment
18

Week 8: Linear 4) Applying for permits to put up a factory is an 11 step process. Some steps depend on 2 points
Programming others, as described below.
and Network
Flows Step 1 must be completed before steps 3 and 4 start.
Step 2 must be completed before steps 3, 6 and 7 start.
Week 8: Step 3 must be completed before step 7 starts.
Intractability
Step 4 must be completed before step 5 starts.
Step 5 must be completed before step 7 starts.
Week 8 Quiz
Step 7 must be completed before steps 8 and 9 start.
Step 9 must be completed before steps 10 and 11 start.
TEXT
TRANSLATION Each step takes a week to complete. What is the minimum number of weeks required to get all the
permits in place?

No, the answer is incorrect.


Score: 0
Feedback:
Construct the DAG and identify the longest path.
Accepted Answers:
6

5) An undirected graph G has 300 nodes and the minimum degree of any vertex is 3. Which 2 points
of the following is the most precise statement we can make about m, the number of edges in G?

m is at least 900.

m is at least 450.

m is at least 300.

m is at least 100.

2 of 3 Friday 09 November 2018 01:13 PM


Design and analysis of algorithms - - Unit 10 - ... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

No, the answer is incorrect.


Score: 0
Feedback:
300 × 3 = 900. Each edge is counted twice, so the number of edges is at least 450.
Accepted Answers:
m is at least 450.

End

3 of 3 Friday 09 November 2018 01:13 PM


18/07/2018 Design And Analysis Of Algorithms - - Unit 12 - Week 4 Quiz

reviewer1@nptel.iitm.ac.in ▼

Courses » Design And Analysis Of Algorithms

Announcements Course Ask a Question Progress Mentor

Unit 12 - Week 4
Quiz

Course
outline Week 4 Quiz
The due date for submitting this assignment has passed. Due on 2018-03-07, 23:59 IST.
How to access
the portal Submitted assignment

Week 1: All questions carry equal weightage. You may submit as many times as you like within the deadline.
Introduction Your final submission will be graded.

1) We are given a directed graph, using an adjacency list representation. The graph has no 2 points
Week 1: Analysis
of algorithms isolated vertices, so every vertex is connected to at least one other vertex. We want to construct an
adjacency list representation of the graph with all edges reversed. That is, the new graph will have an
Week 1 Quiz edge (v, u) whenever the original graph has an edge (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
Week 2: number of edges.)
Searching and
sorting O(n)
O(nm)
Week 2 Quiz O(n2)
O(m)
Week 2
Programming No, the answer is incorrect.
Assignment
Score: 0

Week 3: Graphs Feedback:


We can do this in a single scan of the original adjacency list. Whenever we see an edge (u,v) in the origin
Week 3 Quiz adjacency list, we append (v,u) to the list of edges from v in the new graph. Note that these edges will also
be correctly added in ascending order of the target vertex for each source vertex.
Week 3 Accepted Answers:
Programming O(m)
Assignment
2) An airline charges a different price for each direct flight, depending on the sector. For each 2 points
Week 4: sequence of hopping flights, the ticket price is the sum of the fares of the individual sectors. TripGuru
Weighted graphs 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 17% luxury service
Week 4 Quiz charge to the cost of each individual flight. Which of the following most accurately describes the impact
Quiz : Week 4
of this surcharge on TripGuru's computation?
Quiz
There is no impact. Cheapest routes between all pairs of cities remains unchanged.
Week 4 The precomputed cheapest route may not longer be optimal where there is a shorter route in
Programming terms of number of flights.
Assignment
The precomputed cheapest route may not longer be optimal where there is a longer route in
terms of number of flights.
Week 5: Data
Structures: The impact is unpredictable.
Union-Find and
Heaps No, the answer is incorrect.
Score: 0
Feedback:

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=139&assessment=140 1/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 12 - Week 4 Quiz
The surcharge increases the cost of every path uniformly by 17%, so there is no change in the relative
Week 5: Divide
and Conquer order of paths in terms of cost.
Accepted Answers:
Week 5 Quiz There is no impact. Cheapest routes between all pairs of cities remains unchanged.

3) An airline charges a different price for each direct flight, depending on the sector. For each 2 points
Week 6: Data
Structures: sequence of hopping flights, the ticket price is the sum of the fares of the individual sectors. TripGuru
Search Trees 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 fixed an airport landing fee that
Week 6: Greedy has to be added to the cost of each individual flight. Which of the following most accurately describes the
Algorithms impact of this surcharge on TripGuru's computation?

Week 6 Quiz There is no impact. Cheapest routes between all pairs of cities remains unchanged.
The precomputed cheapest route may not longer be optimal where there is a shorter route in
Week 6 terms of number of flights.
Programming
Assignment The precomputed cheapest route may not longer be optimal where there is a longer route in
terms of number of flights.
Week 7: Dynamic The impact is unpredictable.
Programming
No, the answer is incorrect.
Week 7 Quiz Score: 0
Feedback:
Week 7 The landing fee adds up across sectors, so the impact on the overall cost of route depends on the numbe
Programming of sectors. The surcharge favours hopping flights with fewer sectors.
Assignment
Accepted Answers:
Week 8: Linear The precomputed cheapest route may not longer be optimal where there is a shorter route in terms of
Programming number of flights.
and Network
Flows 4) The Bellman-Ford algorithm cannot be used if a graph has negative cycles. This is 2 points
because:
Week 8:
Intractability The algorithm only runs for n iterations, where n is the number of vertices.
Dealing with negative cycles requires examining all paths exhaustively, which takes esponential
Week 8 Quiz time.
The notion of a shortest path is not well-defined if there are negative cycles.
Download To handle negative cycles, we need to compute all-pairs shortest paths.

TEXT No, the answer is incorrect.


TRANSLATION Score: 0
Feedback:
If there is a negative cycle, each traversal of the cycle results in a shorter overall length, so the shortest
path problem is not well-defined.
Accepted Answers:
The notion of a shortest path is not well-defined if there are negative cycles.

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, and TP is different from TK.
Which of the following must be true?

If e is a minimum cost edge in G, e belongs to both TP and TK.


If e is a maximum cost edge in G, e belongs to neither TP nor TK.
All edges in G have the same weight.
Some pair of edges in G have the same weight.

No, the answer is incorrect.


Score: 0
Feedback:
If edge weights are distinct, the spanning tree is unique. As a counterexample for the first two options,
consider a triangle with all edge weights equal. For the third option, consider a square with opposite edges
having equal weights, but adjacent edges not equal.
Accepted Answers:
Some pair of edges in G have the same weight.

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=139&assessment=140 2/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 12 - Week 4 Quiz

End

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

Powered by

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=139&assessment=140 3/3
Design and analysis of algorithms - - Unit 17 - ... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

reviewer3@nptel.iitm.ac.in ▼

Courses » Design and analysis of algorithms

Announcements Course Ask a Question Progress Mentor FAQ

Unit 17 - Week
5 Quiz

Course
outline
Week 5 Quiz
The due date for submitting this assignment has passed.
How to access As per our records you have not submitted this Due on 2018-10-03, 23:59 IST.
the portal assignment.

Week 1: All questions carry equal weightage. You may submit as many times as you like within the
Introduction deadline. Your final submission will be graded.

Week 1: 1) Suppose we want to extend the union-find data structure to support the operation 2 points
Analysis of Reset(c), which takes as input the name of a component c and then breaks up c into singleton
algorithms components, like MakeUnionFind(). For instance if c = 3 and c currently consists of {1,3,7}, then
Reset(c) will produce three components called 1, 3 and 7 consisting of {1}, {3} and {7}, respectively.
Week 1 Quiz
Which of the following is correct about the cost of adding Reset(c) to the array and pointer
implementations of union-find discussed in the lecture?
Week 2:
Searching and
sorting Array representation: O(size(c)), Pointer representation: O(size(c))

Array representation: O(size(c)), Pointer representation: O(n)


Week 2 Quiz
Array representation: O(n), Pointer representation: O(size(c))
Week 2
Array representation: O(n), Pointer representation: O(n)
Programming
Assignment No, the answer is incorrect.
Score: 0
Week 3: Graphs
Feedback:
Week 3 Quiz In the array representation we have the list
Members[c] which allows us to update the contents of c in time
Week 3 O(size(c)). In the pointer representation there is no easy
Programming way to identify all elements that belong to component c
Assignment without scanning the entire set, so it takes time O(n)
Accepted Answers:
Week 4:
Weighted graphs Array representation: O(size(c)), Pointer representation: O(n)

2) In the algorithm presented for the closest pair of points problem, we have assumed that no 2 points
Week 4 Quiz two points have the same x or y coordinate. Which of the following steps would become more
complicated to justify without this assumption.
Week 4

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

1 of 3 Friday 09 November 2018 01:11 PM


Design and analysis of algorithms - - Unit 17 - ... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

No, the answer is incorrect.


Powered by
Week 5: Divide
Score: 0
and Conquer
Feedback:
Week 5 Quiz All x-coordinates could be the same, in which case we may need O(n) time for each point in PY to assign it
to QY or RY.
Quiz : Week 5
Quiz Accepted Answers:
Constructing QY and RY from PY in time O(n) in the divide step.
Week 6: Data
Structures: 3) Suppose we want to delete an arbitrary element from a max heap. (Assume we have 2 points
Search Trees auxiliary arrays NodeToHeap[] and HeapToNode[] required for the update() operation.)
Consider the following strategies.
Week 6: Greedy
Algorithms Strategy 1: Remove the element from the array, compress the array and reheapify.
Strategy 2: Update the value of this node to the current maximum value in the heap + 1, then
Week 6 Quiz delete_max.

Week 7: Strategy 1 takes time O(n) and Strategy 2 takes time O(log n)
Dynamic
Programming Strategy 1 takes time O(log n) and Strategy 2 takes time O(n)

Strategy 1 takes time O(n) and Strategy 2 takes time O(n log n)
Week 7 Quiz
Strategy 1 takes time O(n log n) and Strategy 2 takes time O(n)
Week 7
Programming No, the answer is incorrect.
Assignment Score: 0
Feedback:
Week 8: Linear
Compressing the array and heapify both take time O(n), so Strategy 1 takes time O(n). Look up the max
Programming
and Network value in a heap takes time O(1). Updating the node takes time O(log n), and so does delete_max(). So the
Flows second strategy takes time O(log n).
Accepted Answers:
Week 8: Strategy 1 takes time O(n) and Strategy 2 takes time O(log n)
Intractability
4) Suppose we want to support the operations predecessor and successor in a heap. Given 2 points
Week 8 Quiz a value v in the heap, pred(v) tells us the next smaller value currently in the heap and succ(v) tells us
the next larger value currently in the heap.
TEXT
TRANSLATION In both min heaps and max heaps, both operations take time O(n).

In both min heaps and max heaps, both operations take time O(log n).

In a min heap, pred(v) takes time O(log n) and succ(v) takes O(n) whereas in a max heap
pred(v) takes time O(n) and succ(v) takes O(log n).

In a min heap, pred(v) takes time O(n) and succ(v) takes O(log n) whereas in a max heap
pred(v) takes time O(log n) and succ(v) takes O(n).

No, the answer is incorrect.


Score: 0
Feedback:
In either case, there is no obvious way to compute pred(v) and suc(v) without scanning all elements, so
both cases take O(n).
Accepted Answers:
In both min heaps and max heaps, both operations take time O(n).

5) Suppose we do merge sort with a five-way split: divide the array into 5 equal parts, sort 2 points
each part and do a 5 way merge. What would the worst-case complexity of this version be?

O(n2)

O(n2 log5n)

O(n log2n)

O(n (log2n)2)

2 of 3 Friday 09 November 2018 01:11 PM


Design and analysis of algorithms - - Unit 17 - ... https://onlinecourses.nptel.ac.in/noc18_cs37/uni...

No, the answer is incorrect.


Score: 0
Feedback:
The recurrence will yield O(n log5 n), but log5 n = log2 n / log2 5 = O(log2 n).
Accepted Answers:
O(n log2n)

End

3 of 3 Friday 09 November 2018 01:11 PM


18/07/2018 Design And Analysis Of Algorithms - - Unit 19 - Week 6 Quiz

reviewer1@nptel.iitm.ac.in ▼

Courses » Design And Analysis Of Algorithms

Announcements Course Ask a Question Progress Mentor

Unit 19 - Week 6
Quiz

Course
outline Week 6 Quiz
The due date for submitting this assignment has passed. Due on 2018-03-21, 23:59 IST.
How to access
the portal Submitted assignment

Week 1: All questions carry equal weightage. You may submit as many times as you like within the deadline.
Introduction Your final submission will be graded.

1) Suppose we do not have a parent pointer in the nodes of a search tree, only left-child and 2 points
Week 1: Analysis
of algorithms right-child. Which of the following operations can be computed in time O(log n) for a balanced search
tree?
Week 1 Quiz
All of find, insert, delete, min, max, pred, succ

Week 2: find, insert, delete, min, max, but not pred, succ
Searching and find, insert, delete, but not min, max, pred, succ
sorting find, insert, delete, pred, succ but not min, max

Week 2 Quiz No, the answer is incorrect.


Score: 0
Week 2 Feedback:
Programming
The only operations that were explained using the parent link were pred/succ, in the case where the node
Assignment
was a minimum/maximum node in its subtree. But we can find the appropriate ancestor by a second scan
Week 3: Graphs from root to this node by checking where the path takes the last right/left turn.
Accepted Answers:
Week 3 Quiz All of find, insert, delete, min, max, pred, succ

2) Postorder traversal prints a tree by recursively listing the values of the left and right 2 points
Week 3
Programming subtrees and then listing the value at the root.
Assignment
function postOrder(t)
Week 4: if (t != NIL)
Weighted graphs postOrder(t.left)
postOrder(t.right)
Week 4 Quiz print(t.value)

Week 4 What is the complexity of postorder traversal for a binary search tree with n nodes?
Programming
Assignment O(log n) if the tree is balanced, O(n) otherwise.
O(n) if the tree is balanced, O(n log n) otherwise.
Week 5: Data O(n) whether the tree is balanced or unbalanced.
Structures:
O(log n) whether the tree is balanced or unbalanced.
Union-Find and
Heaps No, the answer is incorrect.
Score: 0
Week 5: Divide
and Conquer Feedback:
Postorder traversal visits and lists each element once, so it is O(n).

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=147&assessment=148 1/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 19 - Week 6 Quiz
Accepted Answers:
Week 5 Quiz
O(n) whether the tree is balanced or unbalanced.

Week 6: Data 3) Consider the following algorithm to build a balanced search tree from a sorted sequence. 2 points
Structures:
Search Trees Make the mid-point of the sequence the root of the tree
Recursively construct balanced search trees from elements to the left and right of the midpoint
Week 6: Greedy and make these the left and right subtrees of the root.
Algorithms
What is the complexity of this procedure where the sorted sequence is a sorted array?
Week 6 Quiz
Depends on the contents of the original sequence
Quiz : Week 6 O(n)
Quiz
O(n log n)
Week 6 O(n2)
Programming
Assignment No, the answer is incorrect.
Score: 0
Week 7: Dynamic Feedback:
Programming The recursive construction has the recurrence T(n) = 2T(n/2) + O(1) since we can find the midpoint of an
array in constant time.
Week 7 Quiz
Accepted Answers:
Week 7 O(n)
Programming
4) Consider the following algorithm to build a balanced search tree from a sorted sequence. 2 points
Assignment
Make the mid-point of the sequence the root of the tree
Week 8: Linear Recursively construct balanced search trees from elements to the left and right of the midpoint
Programming
and make these the left and right subtrees of the root.
and Network
Flows What is the complexity of this procedure where the sorted sequence is a sorted list?

Week 8: Depends on the contents of the original sequence.


Intractability
O(n)
O(n log n)
Week 8 Quiz
O(n2)
Download
No, the answer is incorrect.
Score: 0
TEXT
TRANSLATION Feedback:
The recursive construction has the recurrence T(n) = 2T(n/2) + O(n), like merge sort, since it takes time
O(n) to find the midpoint in a list.
Accepted Answers:
O(n log n)

5) Which of the following is not a greedy algorithm? 2 points

Kruskal's algorithm for minimum cost spanning tree


Prim's algorithm for minimum cost spanning tree
Floyd-Warshall algorithm for all pairs shortest paths
Dijkstra's algorithm for single source shortest paths

No, the answer is incorrect.


Score: 0
Feedback:
Floyd-Warshall efficiently tests all possible paths of length upto n-1 between every pair of nodes, so it is n
greedy.
Accepted Answers:
Floyd-Warshall algorithm for all pairs shortest paths

End

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=147&assessment=148 2/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 19 - Week 6 Quiz

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

Powered by

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=147&assessment=148 3/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 22 - Week 7 Quiz

reviewer1@nptel.iitm.ac.in ▼

Courses » Design And Analysis Of Algorithms

Announcements Course Ask a Question Progress Mentor

Unit 22 - Week 7
Quiz

Course
outline Week 7 Quiz
The due date for submitting this assignment has passed. Due on 2018-03-28, 23:59 IST.
How to access
the portal Submitted assignment

Week 1: All questions carry equal weightage. You may submit as many times as you like within the deadline.
Introduction Your final submission will be graded.

Week 1: Analysis Your final exams are over and you are catching up on sports on TV. You have a schedule of
of algorithms interesting matches from all over the world during the next week. You hate to start or stop watching a
match midway, so your aim is to watch as many complete matches as possible during the week.
Week 1 Quiz Suppose there are n such matches {M1,M2,…,Mn} available during the coming week. The matches
are ordered by starting time, so for each i ∈ {1, 2, …, n−1}, Mi starts before Mi+1. However, match Mi
Week 2:
Searching and may not end before Mi+1 starts, so for each i ∈ {1,2,…,n−1}, Next[i] is the smallest j > i such that Mj
sorting starts after Mi finishes.

Week 2 Quiz Given the sequence {M1, M2, … , Mn} and the values Next[i] for each i ∈ {1, 2, …, n−1}, your aim is
to compute the maximum number of complete matches that can be watched.
Week 2
Programming 1) Let Watch[i] denote the maximum number of complete matches that can be watched among 2 points
Assignment {Mi, Mi+1, …, Mn}. Which of the following is a correct recursive formulation of Watch[i]?

Week 3: Graphs
Watch[n] = 1
Week 3 Quiz Watch[i] = max(Watch[N ext[i]], 1 + Watch[i + 1]), i ∈ {1, 2, …, n−1}

Week 3
Programming Watch[1] = 1
Assignment Watch[i] = max(Watch[i − 1], 1 + Watch[Next[i − 1]]), i ∈ {2, 3, …, n}

Week 4:
Watch[n] = 1
Weighted graphs
Watch[i] = max(1 + Watch[Next[i]], Watch[i + 1]), i ∈ {1, 2, …, n−1}
Week 4 Quiz
Watch[1] = 1
Week 4 Watch[i] = max(Watch[i − 1] + 1, Watch[Next[i − 1]]), i ∈ {2, 3, …, n}
Programming
Assignment No, the answer is incorrect.
Score: 0
Week 5: Data
Structures: Feedback:
Union-Find and Either watch match i and continue from Next[i] or skip match i and continue from match i+1.
Heaps
Accepted Answers:
Watch[n] = 1
Week 5: Divide
and Conquer Watch[i] = max(1 + Watch[Next[i]], Watch[i + 1]), i ∈ {1, 2, …, n−1}

2) What is the size of the memo table for this problem? 2 points

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=153&assessment=154 1/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 22 - Week 7 Quiz

Week 5 Quiz n-1


n
Week 6: Data n+1
Structures:
Search Trees n2

No, the answer is incorrect.


Week 6: Greedy Score: 0
Algorithms
Feedback:
Week 6 Quiz The recursive function has a single argument ranging from 1 to n, so we need a one dimensional table of
size n.
Week 6 Accepted Answers:
Programming n
Assignment
3) What is a good order to compute Watch[i] using dynamic programming? 2 points
Week 7: Dynamic
Programming From Watch[1] to Watch[n]
From Watch[n] to Watch[1]
Week 7 Quiz Either from Watch[1] to Watch[n] or from Watch[n] to Watch[1]
Quiz : Week 7 None of these
Quiz
No, the answer is incorrect.
Week 7 Score: 0
Programming Feedback:
Assignment
The base case is Watch[n], so start with Watch[n] and work backwards to Watch[1].

Week 8: Linear Accepted Answers:


Programming From Watch[n] to Watch[1]
and Network
Flows 4) How much time will it take to compute Watch[1] using dynamic programming? 2 points

Week 8: O(n3)
Intractability O(n2)
O(n log n)
Week 8 Quiz
O(n)
Download No, the answer is incorrect.
Score: 0
TEXT
TRANSLATION Feedback:
The table is of size n and can be filled in a single pass. Each entry Watch[i] requires checking two values,
Watch[i+1] and Watch[Next[i]], so the time taken is O(n).
Accepted Answers:
O(n)

5) Suppose the list of matches to be watched is presented in the form 2 points

[(11,55),(22,31),(33,45),(44,52),(56,62),(57,58),(59,63),(64,70),(71,80)]

where each match Mi is represented by a pair (Si,Ti) indicated its starting time and ending time.
To be able to watch both Mi and Mj, for j > i, it must be the case that Sj > Ti.

What is the maximum number of matches you can watch in this case?

4
5
6
7

No, the answer is incorrect.


Score: 0
Feedback:
Evaluate the recurrence. The values of Watch[i] as a list are

[6, 6, 5, 5, 4, 4, 3, 2, 1]

Accepted Answers:

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=153&assessment=154 2/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 22 - Week 7 Quiz
6

End

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

Powered by

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=153&assessment=154 3/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 26 - Week 8 Quiz

reviewer1@nptel.iitm.ac.in ▼

Courses » Design And Analysis Of Algorithms

Announcements Course Ask a Question Progress Mentor

Unit 26 - Week 8
Quiz

Course
outline Week 8 Quiz
The due date for submitting this assignment has passed. Due on 2018-04-04, 23:59 IST.
How to access
the portal Submitted assignment

Week 1: All questions carry equal weightage. You may submit as many times as you like within the deadline.
Introduction Your final submission will be graded.

1) When we model a graph problem using LP, mapping each path to a variable is not a good 2 points
Week 1: Analysis
of algorithms strategy because:

Paths can be hard to compute.


Week 1 Quiz
A graph has exponentially many paths.
Week 2: We have to be careful to avoid cycles.
Searching and Edges may be directed.
sorting
No, the answer is incorrect.
Week 2 Quiz Score: 0
Feedback:
Week 2 Graphs have exponentially many paths, so the LP model will have exponentially many variables.
Programming
Assignment Accepted Answers:
A graph has exponentially many paths.
Week 3: Graphs
2) Which of the following is a linear constraint? 2 points

Week 3 Quiz
5y + 3x2 ≥ 33
17x + 3xz ≤ 4
Week 3
Programming 7x ≤ 3xy + 14z - 12
Assignment 3x ≥ 14y + 2z + 13

Week 4: No, the answer is incorrect.


Weighted graphs Score: 0
Feedback:
Week 4 Quiz
In a non-linear constraint, we have two or more variables (same or different) multiplied together.

Week 4 Accepted Answers:


Programming 3x ≥ 14y + 2z + 13
Assignment
3) Suppose we compute the maximum s-t flow F in a network. Then, which of the following is 2 points
Week 5: Data true of s-t cuts?
Structures:
Union-Find and From F, we know the capacity of the minimum s-t cut, but identifying such a cut can take
Heaps exponential time.
F gives a lower bound for the capacity of the minimum s-t cut but not the exact capacity.
Week 5: Divide From F, we can identify a minimum s-t cut in polynomial time.
and Conquer
From F, we can identify all minimum s-t cuts in polynomial time.

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=158&assessment=159 1/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 26 - Week 8 Quiz
No, the answer is incorrect.
Week 5 Quiz
Score: 0

Week 6: Data Feedback:


Structures: From F, use BFS to identify saturated edges that form a min-cut. There may be other min-cuts.
Search Trees
Accepted Answers:
From F, we can identify a minimum s-t cut in polynomial time.
Week 6: Greedy
Algorithms 4) We wish to show that problem B is NP-complete. Which of the following facts is sufficient to 2 points
establish this.
Week 6 Quiz
There is a polynomial time reduction from B to SAT.
Week 6 There is a polynomial time reduction from SAT to B
Programming
Assignment There is a polynomial time reduction from B to SAT, and B has a checking algorithm.
There is a polynomial time reduction from SAT to B, and B has a checking algorithm.
Week 7: Dynamic
Programming No, the answer is incorrect.
Score: 0
Week 7 Quiz Feedback:
We need a reduction from an NP-complete problem to B and evidence that B belongs to NP.
Week 7 Accepted Answers:
Programming
Assignment There is a polynomial time reduction from SAT to B, and B has a checking algorithm.

5) We have constructed a polynomial time reduction from problem A to problem B. Which of 2 points
Week 8: Linear the following is a valid inference?
Programming
and Network If we have a polynomial time algorithm for A, we must also have a polynomial time algorithm for
Flows
B.

Week 8: If we don’t know whether there is a polynomial time algorithm for B, there cannot be a
Intractability polynomial time algorithm for A.
If the best algorithm for A takes exponential time, there is no polynomial time algorithm for B.
Week 8 Quiz If the best algorithm for B takes exponential time, there is no polynomial time algorithm for A.
Quiz : Week 8 No, the answer is incorrect.
Quiz
Score: 0
Download Feedback:
If we have a polynomial time solution for B, the reduction gives us a polynomial time solution for A.
TEXT Accepted Answers:
TRANSLATION
If the best algorithm for A takes exponential time, there is no polynomial time algorithm for B.

End

© 2014 NPTEL - Privacy & Terms - Honor Code - FAQs -


A project of In association with

Funded by

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=158&assessment=159 2/3
18/07/2018 Design And Analysis Of Algorithms - - Unit 26 - Week 8 Quiz

Powered by

https://onlinecourses.nptel.ac.in/noc18_cs20/unit?unit=158&assessment=159 3/3

You might also like