Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Birla Institute of Technology and Science-Pilani, Hyderabad Campus

Second Semester 2021-22


Midterm
Course No CS F364 Course Title: Design and Analysis of Algorithms
Type: Closed Time: 90 min Total Marks:105 (35% ) Date: 15/3/21

Name: ID:
Instruction: Attempt all the questions.
1. (25 points) 1. Solve the following recurrence to get the best asymptotic bounds you can on T (n) in
each case using O() notation.
n
(a) (5 marks) T (n) = T ( 4 log ) + 2n for n > 1 and T (1) = 1. You can assume that all numbers
2n
are rounded down to their nearest integer.
(b) (10 marks) T (n) ≤ T (⌈ n2 ⌉) + T (⌊ n2 ⌋) + cn log n, for n ≥ 4 and T (2) = 2,(Do not use Master
theorem here).
2. Prove or disprove the following;
(a) (5 Marks) o(g(n)) ∩ ω(g(n)) = ∅.
(b) (5 Marks) Let f (n) and g(n) be asymptotically positive functions. If f (n) = O(g(n)) then
2f (n) = O(2g(n) ).

2. (25 points) 1. Given an unsorted array of all integers in the range 0 to n (= 2k − 1) except for one
integer (called missing integer), where all non-missing integers appear once only.
(a) (10 Marks) Design a O(n) Divide and Conquer algorithm to find the missing number. No credit
will be given for non Divide and Conquer algorithms.
(b) (4+3 Marks) Argue (informally) that your algorithm is correct and analyze its running time.
2. (8 Marks) Consider the following Divide and Conquer algorithm for computing minimum spanning
tree. Given an undirected weighted graph G(V, E), partition the vertex set into V1 and V2 such
that |V1 | and |V2 | differ by at most 1. Let E1 ⊆ E be the set of edges which are incident only on
vertices in V1 , E2 ⊆ E be the set of edges which are incident only on vertices in V2 . Recursively
solve a Minimum Spanning Tree problem on each of the two subgraphs G1 (V1 , E1 ) and G2 (V2 , E2 ).
Finally, select the minimum-weight edge in E that crosses the cut (V1 , V2 ), and use this edge to
unite the resulting two minimum spanning tree into a single spanning tree. Either argue that this
algorithm is correct or disprove it using a counter example.
3. (15 points) 1. (7 Marks) Let P be a set of n points in the plane. Suppose we have h points of P as
the only vertices of the convex hull of P . Assume that you are given these h points c1 , c2 , . . ., ch
in clockwise order as they appear on the boundary of the hull. Give an O(log h) time algorithm to
determine if a new point p is within the convex hull. Give an O(h) time algorithm to find the new
convex hull, i.e., the convex hull of the point-set P ∪ {p}
2. (8 Marks) Given a convex polygon P with n boundary points, find the longest segment that fits
inside P . Your algorithm should run no worse than O(n log n) time.
4. (20 points) We are given a set of n jobs J1 , J2 , . . . , Jn and each job Ji is associated with a processing
time pi and the deadline di where pi , di are positive integers such that pi ≤ di . Further, all the jobs are
available at the beginning (that is time 0). We are also given a single machine where these jobs to be
processed. Note that, at a given point of time only one job can be scheduled on the machine and further,
if a job is started then it must run on the machine till it finishes. The goal is to find a scheduling of the
jobs J1 , J2 , . . . , Jn on the machine such that the maximum number of jobs finish on or before respective
deadlines.
1. (4 Marks) Greedy strategy 1 (Shortest Job First): execute the shortest job first and then iterate
it over other remaining jobs. Show that the shortest job first strategy does not always return an
optimal solution.
2. (4 Marks) Greedy strategy 2 (Earliest Deadline First): execute the job with earliest deadline
first and then iterate it over other remaining jobs. Show that the earliest job first strategy does not
always return an optimal solution.
3. (4+6+2 Marks) Consider a special case of the problem with the processing time of each job is one
i.e., pi = 1 for all i = 1, 2, . . . , n. Design a polynomial-time greedy algorithm for the problem which
returns an optimum solution for all the instances of the problem. Prove the correctness of your
algorithm. Further, give the running time of your algorithm.

5. (20 points) 1. (a) (1 Marks) State the cut property based on any cut (S, V − S), such that S and
V −S are non-empty, to guarantee the existence of an edge e = (v, w) in the Minimum Spanning
Tree of an undirected weighted graph with distinct weights, such that v ∈ S and w ∈ V − S.
(b) (6 Marks) Now consider the following proof of the cut property. Let T be a spanning tree that
does not contain the edge e = (v, w), which satisfies the cut-property. Since T is a spanning
tree, it must contain an edge f with one end in S and the other end in V − S. Since e satisfies
cut-property, we have weight(e) < weight(f ), and hence T − {f } + {e} is a spanning tree that
is cheaper than T .
What is wrong with this proof? Explain with the help of an example.
(c) (5 Marks) Please do the necessary changes to the above proof to make it correct.
2. (8 Marks) Consider an undirected weighted graph where all edge weights are positive and are not
necessarily distinct. It means, there can be more than one Minimum Spanning Trees of this graph.
Let T be a spanning tree of G such that every edge of T is an edge of some MST. Is T also an MST
of G? Prove or disprove with the help of a counterexample.

Page 2

You might also like