DAA Group Assignment

You might also like

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

Shiv Nadar University

Computer Science and Engineering


Design and Analysis of Algorithms CSD319
Group Assignment

Monsoon 2022-23, 6th Semester

1. We are given n points in the unit disk, pi = (xi , yi ), such that 0 < x2 + y2 ≤ 1 for i ∈
1, 2 · · · , n. Suppose that the points are uniformly distributed; that is, the probability of
finding a point in any region of the circle is proportional to the area of that region. Design
an algorithm with q an average-case running time of Θ(n) to sort the n points by their
distances di = xi2 + y2i from the origin. (Hint: Use ideas from the BUCKET-SORT.) (4)

2. Suppose that we insert n keys into a hash table of size m using open addressing and
uniform hashing. Let p(n, m) be the probability √ that no collisions occur. Show that
p(n, m) ≤ e −n(n−1)/2m . Argue that when n exceeds m, the probability of avoiding colli-
sions goes rapidly to zero. (4)

3. Longest palindrome subsequence.


Give an efficient algorithm to find the longest palindrome that is a subsequence of a given
input string. Explain the running time of your algorithm?
A palindrome is a nonempty string over some alphabet that reads the same forward and
backward. Examples of palindromes are all strings of length 1, madam, kayak, and aiboh-
phobia (fear of palindromes) etc... For example, given the input character, your algorithm
should return carac. (4)

4. Bitonic euclidean traveling-salesman problem


In the euclidean traveling-salesman problem, we are given a set of n points in the plane,
and we wish to find the shortest closed tour that connects all n points. Figure 1(a) shows
the solution to a 7-point problem. The general problem is NP-hard, and its solution is
therefore believed to require more than polynomial time.
However, if we simplify the problem by restricting our attention to bitonic tours, that is,
tours that start at the leftmost point, go strictly rightward to the rightmost point, and then
go strictly leftward back to the starting point. Figure 1(b) shows the shortest bitonic tour
of the same 7 points. In this case, a polynomial-time algorithm is possible. Describe an
O(n2 )-time algorithm for determining an optimal bitonic tour. You may assume that no
two points have the same x-coordinate and that all operations on real numbers take unit
time. (4)
Figure 1: There are seven points in the plane, shown on a unit grid. (a) The shortest closed
tour, with length approximately 24:89. This tour is not bitonic. (b) The shortest bitonic tour
for the same set of points. Its length is approximately 25:58.

5. Design an algorithm to solve the fractional knapsack problem in O(n) time. Prove the
correctness of your algorithm and analyse the run-time. (4)

6. Given a set {a1 , a2 , · · · , an } of n points on the real line, design an efficient algorithm that
returns the smallest set of unit-length closed intervals that contains all of the given points.
Prove the correctness of your algorithm and analyse the run-time. (4)

7. Let G be a weighted undirected graph and T is a minimum spanning tree of G, suppose


that we decrease the weight of one of the edges of G not in T . Give an efficient algorithm
for finding the minimum spanning tree in the modified graph. (4)

8. Show that a graph has a unique minimum spanning tree if, for every cut of the graph, there
is a unique minimum weight crossing edge. Show that the converse is not true by giving a
counterexample. (4)

9. Given two positive n digit integers, a and b. Design an algorithm that multiplies a and b
in O(n1.58 ) time. (Hint: Use divide and conquer technique.)
The usual (primary school) approach to multiply the two numbers takes O(n2 ) time be-
cause we need to multiply each digit in one number with those in the second number, put
them in the correct position.

10. Given n chords on a circle, each defined by its endpoints. Describe an O(n log2 (n)) time
algorithm to determine the number of pairs of chords that intersect inside the circle. As-
sume that no two chords share an endpoint. For example, if the n chords are all diameters
n
then they meet at the center and the total intersection is 2 . (4)

Page 2

You might also like