DAA 2020 Week 05 Assignment 01
DAA 2020 Week 05 Assignment 01
(https://swayam.gov.in) (https://swayam.gov.in/nc_details/NPTEL)
Course
outline Week 5 Quiz
How does an The due date for submitting this assignment has passed. Due on 2020-03-04, 23:59 IST.
NPTEL online As per our records you have not submitted this assignment.
course work?
All questions carry equal weightage. You may submit as many times as you like within the deadline.
Week 1 : Your final submission will be graded.
Introduction
1) An image is represented as an N×N array A of pixels. There is a function that transforms the 2 points
image as follows:
Week 1 : Analysis
of algorithms The function scans each pixel A[i][j]. Depending on the current value of A[i][j], some
values in row i and column j are updated. It is possible that all values in row i and column j are
Week 1 Quiz updated. It is also possible that no values are updated.
Updating a pixel takes time O(log N).
Week 2 : Each pixel in the image is updated at most once by the function.
Searching and What is the best upper bound you can estimate for the total time taken across all the updates made by the
sorting function?
https://onlinecourses.nptel.ac.in/noc20_cs27/unit?unit=112&assessment=113 1/3
02/07/2020 Design and analysis of algorithms - - Unit 16 - Week 5 Quiz
O(N2 log N)
Week 4 :
Weighted graphs 2) In the Union-Find data structure, suppose we want to add an operation reassign(j,k) 2 points
that moves item j to the same component as item k. What would be the complexity of this operation for a
Week 4 Quiz set with n elements?
Week 4 O(1) for both the array representation and the pointer representation.
Programming O(1) for the array representation, but not O(1) for the pointer representation.
Assignment O(1) for the pointer representation, but not O(1) for the array representation.
Not O(1) for either the array representation or the pointer representation.
Week 5: Data
Structures: No, the answer is incorrect.
Union-Find and Score: 0
Heaps Feedback:
In the array representation, we have to assign Component[j] the same value as Component[k]. In the
pointer representation, we look up Node[j] and Node[k] and copy the parent pointer from Node[k] to Node[j]
Week 5 : Divide
So both these updates take time O(1).
and Conqure
However, in the array representation we also have to update members[i] for both components, which will
Week 5 Quiz take time proportional to the sizes of the components, so it is not a constant time operation.
In the pointer representation we also have to shift the pointer of the children of j to the parent of j. Since j
Quiz : Week 5
could have multiple children, this is again not a constant time operation.
Quiz
(assessment? Accepted Answers:
name=113) Not O(1) for either the array representation or the pointer representation.
Week 6: Data 3) In a min-heap, what is the most accurate description of the worst-case complexity of the 2 points
Structures: operation find_max that reports the value of the largest element in the heap, without removing it?
Search Trees
O(1)
[82,42,32,27,25,18,25,27]
Week 7
Programming [82,27,42,32,25,18,25,27]
Assignment [82,42,27,25,32,18,25,27]
[82,42,27,32,25,18,25,27]
Week 8: Linear
No, the answer is incorrect.
Programming Score: 0
and Network
Feedback:
Flows The leaf node where 57 was inserted was the last one, which is currently 32. The path from the current
position of 57 to this leaf goes via the node with value 42. So we have to undo the swap made along this
Week 8: path when inserting 57.
Intractability
Accepted Answers:
[82,42,27,32,25,18,25,27]
Week 8 Quiz
5) Consider an alternative to binary search called ternary search that divides the input array into 2 points
three equal parts and recursively searches one of these three segments. What can we say about the
https://onlinecourses.nptel.ac.in/noc20_cs27/unit?unit=112&assessment=113 2/3
02/07/2020 Design and analysis of algorithms - - Unit 16 - Week 5 Quiz
which resolves as T(n) = O(log3n). However, since log3n = log2n/log23, the asymptotic complexity is the
same as O(log2n) for binary search.
Accepted Answers:
The complexity of ternary search is the same as that of binary search.
https://onlinecourses.nptel.ac.in/noc20_cs27/unit?unit=112&assessment=113 3/3