You are on page 1of 6
Gb. Copy t4)acfor [bis question paper contains 10 printed pages.) Your Roll Nes eonnsn Se. No. af Question Paper: 1143 a Unique Paper Code sasaraoi Name of the Paper Design and Analysis of Algorithns Name of the Course: BS. (I) Computer Science Semester wv Duration: 3 Hours Manion Marks : 75 instructions fo 1 Write your Roll No: on the top immediatly on receipt of this question paper. 2, Question No. £ is compulsory 3. Auenmpt any four of Questions Nes. 2 to 8 1. (0) Consider the recursive algorithm as follows 19 of Insertion sort, In order to sort Afi a], we recursively sort ATL orl] and then insert Af] into the sorted array A[] ml]. Write a recurrence for the running time of this algorithm. 8 Pro. 1143 2 (6) What ate the m lements in a binary heap of height BY. 2) Jima and maximum number of (©) Which of the following algorithms are stable Insertion sort, Queksort? Justify with te help of sn example. ® (@) What are these key factors that decide whether Dynamic Programming is applicable for sn ‘optimization problem or not? e (©) “The minimum spanning tree im a graph is not always unique" Justify. Give a graph with $ nodes that has two different minimum spanning tres. @ ( Would you use BFS 10 find the shortest path between two nodes én 2 weighted graph with arbitrary edge weights? Justify your answer sith the help of a graph having at least $ Vertices and at least 7 edges. ° (2) “Counting sort is 4 comparison sort algoriths,” Yes or No. Justiy your answer using the input A=64,3,2,4,1,5,2,43> @ (5) A priority queue can be implemented in two Aitferent ways using min-heap and using singly linked list in which elements are stored in sorted 1143 5 alder (Smaller values indicates higher priority) Compare the time complexity of following operations when performed on two differe implementations of priority queue. (1) Finding the highest priority element (2) Deleting the highest priority element (9) Increase the priovity of a certain element © 0) ind posible Topological sons ofthe piven directed graph, Give any four ey i) Give the worst ease for the merge algorithm to merge two sorted strays AL. 4], Blloom) (where n=k+m) and give the total number of comparisons in the worst case (in terms of 1) Merge the two sorted arrays A = [3, 7,9, 12, 14] and B= [2, 5, 6, 10] using morge algorithm. How many number of comparisons are done by the lgorthm in the above extmple? o pro. 1143 4 (8) Consider the Interval Scheduling problem wherein, We ate given a resource and a set of requests cach having a start time and @ finish time, The foal is to maximize the aumiber of requests Scheled, Show that dhe following greedy siratcxy does not give an optiznal solution for the above problem. Greedy strategy: Select the request with fewest ‘number of incompatible requests, ° 2. (a) Peofessor William claims that the Qn fg») lower bound for sorting n numbers docs not apply to his ‘machine, The conttol flow of a program on his ‘machine can split three ways after a single comparison of two elements of the array a,:9, The three ways are 9, < 8) 4 = a, of a > a, Show that the professor is wrong by proving that ‘he numberof three-way comparisons requited to sort m elements is O(w len), 6 () Suppose you have aa algorthts fo find meslian of fr elements of an unsorted ray in O(n) time ia the worst ease, Now consider an implementation ‘of Quicksort where you fits find median using the above algorithm, then use median a pivot ‘What wil be the time complesityof this modified 1143 5 (Quicksort” Write down the recurrence relation to justify your time complexity (Median of elements is the element whose rank is 1/2 if mis even and itis (ntl 2 if mis bd. o 3. (a) llustrate the operation of BUILD -MAX -H EAP on the array A <4, 3,17, 10, 28, 19, 6 12, 7 Wirite down the total number of comparisons done bby BUILD -MAX -t1 EAP, © (©) Consider the following recursive relation for 0-1 knapsack problem, Iw ew, then OPTi,w) = OPT(-1,¥) else OPT, W) = max(OPT(-1,w), ¥, + OPTI, > where OPT(,w) denote the value of the optimal solution using a subset of items (1,2yi} with rmakimum allowed weight w. ¥; fe the cost of ith stem Fl the missing vale, What is the cunning time of the recursive Implementation of the shove recurrence? Justify Give memoized recursive algorith for the above problem, Explain how does it improve the running time? oy pro. 1143 6 4 (@) Give an algorithm to sort a integers in the range 0 to n? 1 in O(n) time. Justify it’s time complexity ® (©) Suppote we use randomized select to select the sminimum elemeat of the arrey A= <4,2,1, 7,8, 12, 3, 0, 9, S, 10>. Describe a sequence of partitions that resull in a worst case performance of randomized sele. ® () Suppose an input to the bucket sort algorithm is sot uniformly distributed. What willbe the effoet of this condition on the running time of the algorithm? Justify @ (2) A Shopkeeper has n emply boxes and M number of balls Let (KK one Kn} denote the wumber of balls that each box can stor, Given Mand (Ky, Ky Kn}, describe a ‘greedy algorithm whick determines the minimum ‘number of boxes needed 10 store the balls. Give time complexity of the algorithm. o () Design 2 O(¥i"1E) time algorithm 1 find whether 2 given undirected graph is.bipartte (where V is the set of vertices, E ie the set of edges of the sap. ” 1143 1 (6) Give space requirements of adjacency matrix and adjacency ist represestation having m edges snd vertices. e) 6 (a) "Prim’s algorithm only inelude an edge in the “Minimum Spanning tree when i is justfie by the Cut propery." State the Cut Property. Justify the above statement on the given graph showing cute iv all the intermediate steps © () Suppose divide and conquer approach is ured hy fan algorithm to solve a problem on the input of size m. The algorithm divides the problem into f number of smaller instznces, exch of which is Yb the size ofthe original problem. It solves prlem reersivey on these smaller instances and combine theit solutions to construct the final Pro, 1143 8 solution ofthe brignal problem. Let Gin) denotes the cost of dividing the problem into smaller instances and Fin) denotes the eost of combining the solutions. Write the recurrence relation to find the running time of the algorithm. Give G(n} and Fn) for Hoth Ouicksort sad Mergesort algorithm, —() (6) Let G be a graph with m vertices and m edges. What is the upper bound on the running time of Depth Firat Search on G, where G is represented as an adjacency matrix? @ [a) A boat fas 9 capaci sms each having ceria weight Wi hit The goal isto select che set of ‘tem thatthe boat should carry so that it could carry maximum load(ie. sum of the weights of selected items should be maximum) within capacity €, © ta carry load. There are si number of sssociated wi Design « Polynomial time Dydumie Programming algorithm for the problem. Derive the time complenty of the above algorithm, Ran this algorithm on the sample iastanee given below to find the optimal solution, 6 1143 9 Capacity of the boat = 4g Hens ‘Weights tem ake Tem 2 ke Them? 1s () Suppose we perform a sequence of » operations tm a data structure in whieh the th operation costs iF Fi am exact power of 2, and 1 otherwise, Use aggregate analysis to determine the amortized cost per operation, o 8.) The following graph represents sework of siports that are connected 10 each other. Each edge epresets the distinee (in multiples of 1000 mies) ‘covered by the igh 0 travel from one aiport to another and vertices represents the airports. A. flight steets from wirport and has to reach Aestinaions c,d and e: Run an efficiet algorithm to Find the route taken by the fligh to exch co is destinations in minimum possible time, Show all the imermodiate steps taken by the algoritha, Also drive its time eompenty o Pro. 1143 10 () There are x Jobs where gach job stats at time 5, and finishes at time fi, There isa profit associated ‘with each job. The goal isto find a subset of nos: ‘overlapping jobs such that the sum of their profits Given below is the instance of the problem: cb Namba [Stat Time | Fash tne] Prot w 0 o oer o 6. @ job 1 a 30 obs 3 5 0 ob 5 7 30 obs 5 3 = Dobe 7 3 w ve a Dynamic programing the shove problem, Explain the recurrence relation sed inthe solution, tive solution for Show that the “Optimal solution to the ahove problem contains within it optimal solution 4 its subproblems.” With reference to the above example © (1500)

You might also like