Professional Documents
Culture Documents
Assignment 2
Assignment 2
ASSIGNMENT 02
Marks: 05
QUESTION 01 (2 Mark)
Demonstrate the optimal solution for the 0/1 knapsack problem making use of dynamic
programming approach. Consider-
n=4
w = 5 kg
(w1, w2, w3, w4) = (2, 3, 4, 5)
(b1, b2, b3, b4) = (3, 4, 5, 6)
QUESTION 02 (1 Mark)
Use the substitution method to show that the recurrence
Has solution
T(n) = O ( n lg lg n )
1|Page
CS Department, BUKC 2 Semester 05 (Fall 2021)
CSC-321: DAA Assignment 02
Let k = n/2
Partition A into B, C where B contains A[1..k-1], and C contains A[k+1..n]
If A[k] == b then b is in array A
If A[k] > b then call binary_search(B, b)
If A[k] < b then call binary_search(C, b)
(a) Analyze the running time of the binary search algorithm.
(b) Using similar ideas, you are going to solve a related problem. In this problem you are given
an array A[1..n] that is first decreasing and then increasing. More precisely, there is a
CS Department, BUKC 4 Semester 05 (Fall 2021)
CSC-321: DAA Assignment 02
coordinate 1 ≤ p ≤ n such that for all i < p, A[i] > A[i + 1], and for all i ≥ p, A[i] < A[i + 1].
Your goal is to find the smallest element in this array. Please design an algorithm that has the
same asymptotic running time as binary search.