practice-sheet6.pdf

Embed Size (px)

Citation preview

  • Data Structures and Algorithms : CS210A, ESO207A, ESO211

    Practice-sheet 6

    Date: 10th November, 2012.

    1. Describe an O(n) time algorithm that given a set S of n distinct numbers and apositive number k n, determines the k numbers in S that are closest to the medianof S.

    2. Let X and Y be two sorted arrays, each containing n distinct numbers. Design anO(log n) time algorithm for computing the median of all 2n elements in arrays X andY .

    3. Thoroughly understand the proof for the average running time of quick sort. Inparticular, you must fully internalize the way the recurrence was formulated for T (n)and solved using induction. What can you say about the average running time forinsertion sort and selection sort ?

    4. You are working with a group of security consultants who are helping to monitor alarge computer system. There is a particular interest in keeping track of processesthat are labeled sensitive. Each such process has a designated start time and finishtime, and it runs continuously between these times; the consultants have a list of theplanned start and finish times of all sensitive processes that will run that day.

    As a simple first step, they have written a program called status check that, wheninvoked, runs for a few seconds and records various pieces of logging informationabout all sensitive processes running on the system at that moment. (Well modeleach invocation of status check as lasting for only this single point of time.) Whattheyd like to do is to run status check as few times as possible during the day,but enough that for each sensitive process P , status check is invoked at least onceduring the execution of process P .

    Give an efficient algorithm that, given the start and finish times of all the sensitiveprocesses, finds as small a set of times as possible at which to invoke status check,subject to the requirement that status check is invoked at least once during eachsensitive process P .

    5. The manager of a large student union on campus comes to you with the followingproblem. She is in charge of a group of n students, each of whom is scheduled towork one shift during the week. There are different jobs associated with these shifts(tending the main desk, helping with package delivery, rebooting cranky informationkiosks, etc.), but we can view each shift as a single contiguous interval of time. Therecan be multiple shifts going on at once.

    She is trying to choose a subset of these n students to form a supervising committeethat she can meet once a week. She considers such a committee to be completeif, for every student not on the committee, that students shift overlaps (at leastpartially) the shift of some student who is on the committee. In this way, eachstudents performance can be observed by at least one person who is serving on thecommittee.

    1

  • Give an efficient algorithm that takes the schedule of n shifts and produces a completesupervising committee containing as few students as possible. You must also provethe correctness of the algorithm.

    6. Suppose we are given a connected graph G, with edge costs that are all distinct. Provethat G has a unique minimum spanning tree.

    7. There is a connected graph G = (V,E), with edge costs that are all distinct. You aregiven a set E of n 1 edges from G which forms a spanning tree T . Furthermore,you are told that exactly n 2 edges of T belong to the minimum spanning tree ofG. Design an O(m+n) time algorithm to compute the minimum spanning tree of G.

    8. A spanning tree of a graph is said to be a maximum spanning tree if its weightis maximum among all spanning trees of the graph. Design efficient algorithms forcomputing maximum spanning tree. How similar are these algorithms to minimumspanning tree ? Are there graph theoretic properties of maximum spanning treessimilar to cut-property and cycle-property of minimums spanning tree ?

    2