You are on page 1of 2
821003: Algorithms - 1 Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Midsem Examination, Autumn 2018 Total Marks: 100 ‘Time: 2 Hours Answer ALL Questions 1. (a) When can you say that /(n) ~ o(g(n))? (Small-oh, not Big-oh). 8) (b) Show the Red-Black tree that is formed after successively inserting 50, 35, 25, 55, 58, 56, 28 into an initially empty Red-Black tree. Just show the trec after cach insertion (so total 7 trees), no explanation is needed. (10) (6) Consider a hashing scheme using quadratic probing, The hash table size is 20 and the hash function used is A(k, i) = ((k mod 20) + 2i + 2i') mod 20. What is the probe sequence and the number of probes needed to insert each of the following elements into the hash table in this order: 10, 30, 32, 38, 54, 50, $8, 27, 92? (Just show the probe sequence and number of probes for each clement, no need to show any calculation or the table contents). (10) (@) Find an optimum parenthesization of the matrix chain AyA2A3AgAs where Ay = 10*25, Ap = 25% 50, Ay = 5035, Ay = 35%100, and As ~ 10050 matrices. Show all calculations. (10) 2. (a) An array A of n integers is said to be unimodal if it can be split into a strictly increasing sequence followed by a strictly decreasing sequence. An cxample is the array 1, 3, 6, 7, 5, 3, 2, 1. Design an O(log n) time algorithm to find the maximum element in an unimodal array (Write the pseudo code of your algorithm). (10) (b) Given an array 4 of n distinct integers, can you create a binary search tree storing all the integers in O(n) time? If yes, provide an algorithm to do so. If not prove why not. (10) (©) Consider a max-heap of n integers stored in an array, and another integer x. Given an integer k (1 0. Once started, the job runs without interruption for L, time in the half-open interval (7), Ty + Lx). Each job k must finish by time Dg, in which case it earns profit P, ; otherwise it earns 0 profit. A feasible schedule is an assignment of start times to a subset of the jobs such that (i) for any time instant, at most one job in the subset is running, and (ii) each job in the subset finishes by its deadline. Note that it may not be possible to schedule all jobs. For example, if all jobs have duration 5 and deadline 10, only two can be scheduled (with assigned start times 0 and 5), and there are "Cp different feasible schedules possible in this case, each with 2 jobs. The total profit of a feasible schedule is the sum of the profits of the jobs in the schedule. Design an O(nD) time dynamic programming algorithm to find the maximum profit among all feasible schedules, where Dis the maximum deadline among all jobs. (20)

You might also like