0% found this document useful (0 votes)
12 views15 pages

Prof Qs V1

The document contains a series of algorithm and graph theory questions that challenge the reader to design efficient algorithms for various computational problems. Topics include squaring integers, finding the k-th smallest element, solving recurrences, ordering functions by asymptotic growth, finding majority elements, shortest paths in graphs, merging sorted arrays, and computing the closest pair of points. The questions require a deep understanding of algorithm design and analysis, as well as graph theory concepts.

Uploaded by

bscs23092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views15 pages

Prof Qs V1

The document contains a series of algorithm and graph theory questions that challenge the reader to design efficient algorithms for various computational problems. Topics include squaring integers, finding the k-th smallest element, solving recurrences, ordering functions by asymptotic growth, finding majority elements, shortest paths in graphs, merging sorted arrays, and computing the closest pair of points. The questions require a deep understanding of algorithm design and analysis, as well as graph theory concepts.

Uploaded by

bscs23092
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Algorithm and Graph Theory Questions

Questions

1
1. Given an n bit integer, write an efficient algorithm to return the square of n. In particular, prove
that time complexity of the product of two numbers is the same as the time complexity of squaring a
number, i.e., if you can square an n bit number in O(f (n)), then you can also take the product of two
n bit numbers in O(f (n)).

2
2. Suppose you are given a “black box” linear-time median finding algorithm. Design a simple linear-
time algorithm to find the k th smallest element using this algorithm. Note that the median-finding
algorithm you are given is black-box, and you can’t change it in any way; you can just call it to find the
median of a list in linear time.

3
3. Solve the following recurrences:
• T (n) = 8T (n/3) + n
• T (n) = 2T (n/2) + n0.5

• T (n) = 3T (n/4) + n log n


• T (n) = T (n − 2) + n2

4
4. Order the following functions according to increasing asymptotic growth and provide a one-line
reason for each consecutive pair: ∗
23n , 32n , n!, 2log n , log∗ 22n

5
5. Given a list of n integers, design an efficient algorithm to find a majority element. A majority
element is an element that appears more than bn/2c times.

6
6. Given an unweighted directed graph G = (V, E) and a source vertex s and a destination vertex t,
design an algorithm to find the shortest path from s to t.

7
7. Given a simple undirected graph G = (V, E), design an algorithm to compute a new graph
H = (V, F ) where (u, v) ∈ F if and only if d(u, v) ≤ 2 in G, i.e., u, v are adjacent in H whenever their
distance is 1 or 2 in the original graph G.

8
8. You are given m arrays A1 , A2 , . . . , Am where each Ai contains n integers in sorted order. Give an
O(nm log m) algorithm to merge these m sorted arrays into a single sorted array. You may use Priority
Queues.

9
9. Given a set P of n two-dimensional points, i.e., each point is represented as (xi , yi ), give an efficient
algorithm to compute the closest pair of points in P , i.e., points in P for which the Euclidean distance
is minimized.

10
10. Solve the following recurrences:
• T (n) = 8T (n/4) + n1.5
• T (n) = 3n T (n/2) + n0.5

11
11. Order the following functions according to increasing asymptotic growth and provide a one-line
reason for each consecutive pair: ∗
23n , 32n , n!, 2log n , log∗ 22n

12
12. Give the runtime complexity of the following algorithm:

Algorithm 1 Recursive Algorithm


procedure Algo1(x)
if |x| > 2 then √
return ALGO1( x)
else
return x
end if
end procedure

13
13. How can you sort n integers in the range [0, n3 − 1] in linear time?

14
14. Design and analyze an algorithm to count the number of triangles in a simple undirected graph
on n vertices.

15

You might also like