Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views2 pages

Compre18 19 Dsa

The document is a comprehensive examination for the CS F211 course at Birla Institute of Technology & Science, covering various topics in Data Structures and Algorithms. It includes questions on analyzing pseudocode for time complexity, sorting algorithms, tree structures, hashing, and matrix operations. The exam consists of multiple parts, each requiring detailed explanations and proofs related to algorithm performance and data structure implementations.

Uploaded by

f20230664
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)
7 views2 pages

Compre18 19 Dsa

The document is a comprehensive examination for the CS F211 course at Birla Institute of Technology & Science, covering various topics in Data Structures and Algorithms. It includes questions on analyzing pseudocode for time complexity, sorting algorithms, tree structures, hashing, and matrix operations. The exam consists of multiple parts, each requiring detailed explanations and proofs related to algorithm performance and data structure implementations.

Uploaded by

f20230664
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/ 2

Birla Institute of Technology & Science - Pilani, Hyderabad Campus

Second Semester 2018-2019


CS F211: Data Structures and Algorithms
Comprehensive Examination
Type: Closed Time: 180 mins Max Marks: 120 Date: 07.05.2019

All parts of the same question should be answered together.

1. Find out the best and worst case running time of the following pseudocode functions in Big-
Oh notation in terms of the variable ‘n’. You need to show the steps leading to the final solution.
a. int silly(int n, int m) {
if (m < 2) return m;
if (n < 1) return n;
else if (n < 10)
return silly(n/m, m);
else
return silly(n - 1, m);
} [4 Marks]
b. void silly(int n, int x, int y) {
for (int k = n; k > 0; k--)
if (x < y + n) {
for (int i = 0; i < n; ++i)
for (int j = 0; j < i; ++j)
System.out.println(”y = ” + y);
} else {
System.out.println(”x = ” + x);
}
} [4 Marks]
1.c. Let processing time of an algorithm of Big-Oh complexity O(f(n)) be directly proportional to
f(n). Let three such algorithms A, B, and C have time complexity O(n2), O(n1.5), and O(n log n),
respectively. During a test, each algorithm spends 10 seconds to process 100 data items. Derive
the time each algorithm should spend to process 10,000 items. [8 Marks]

1.d. Show that when all elements are distinct, the best-case running time of heapsort is Ω(n lg n).
[8 Marks]
2.a. What is the running time of QUICKSORT when all elements of array A have the same
value? [4 Marks]
2.b. Describe an algorithm that, given n integers in the range 0 to k, preprocesses its input and
then answers any query about how many of the n integers fall into a range [a . . b] in O(1) time.
Your algorithm should use Θ(n + k) preprocessing time. [6 Marks]
2.c.. Show how to implement a first-in, first-out queue with a priority queue. Show how to
implement a stack with a priority queue. [6 Marks]
2.d. Devise an algorithm to print out the values stored in all of the leaves of a perfect BST
containing n values in ascending order. [6 Marks]
Perfect BST is BST wherein each leaf is at height log n or (log n) – 1.
3.a. Develop an algorithm that computes the kth smallest element of a set of n distinct integers in
O(n + k logn) time. [6 Marks]
Note: You should solve this problem only by making use of heap.

3.b. The path length of a tree T is the sum of the depths of all the nodes in T. Describe a linear-
time method for computing the path length of a tree T. [8 Marks]

3.c. A hash table with ten buckets with one slot per bucket is shown in Figure 1, with the
symbols S1 to S7 entered into it using some hashing function with linear probing. Find out the
worst case number of comparisons required when the symbol being searched is not in the table.
[4 Marks]

3.d. Prove that the expected cost of a successful search (with collision being resolved by
chaining) in hash table of n elements with m slots is Θ(1 + α) where α is load factor.[8 Marks]

4.a. Suppose there are n elements in array. Devise an algorithm of O(n) complexity to arrange
the elements in the array such that all negative numbers occur before positive numbers. You are
not supposed to use another array in your algorithm. [6 Marks]

4.b. Prove that the height of Red Black tree with n internal nodes is O(log n). [6 Marks]
Note: Need to prove with all details.
4.c. The obvious linear algorithm for exponentiation xn uses n−1 multiplications. Propose a faster
algorithm of O(log n) complexity in the case when n = 2m by writing and solving a recurrence
formula. [10 Marks]

5.a. How quickly can you multiply a kn × n matrix by an n × kn matrix, using Strassen's
algorithm as a subroutine? Answer the same question with the order of the input matrices
reversed (i.e., multiplying n × kn matrix by kn × n matrix). [10 Marks]
Note: If any method other than Strassen’s method is used as part of the solution then no marks
will be awarded.

5.b. Longest Increasing Subsequence. Given a sequence of n real numbers A(1) ... A(n),
determine a subsequence (not necessarily contiguous) of maximum length in which the values in
the subsequence form a strictly increasing sequence. [8 Marks]

5.c. Consider a variant of the matrix-chain multiplication problem in which the goal is to
parenthesize the sequence of matrices so as to maximize, rather than minimize, the number of
scalar multiplications. Does this problem exhibit optimal substructure? Support your answer with
valid arguments. [8 Marks]

You might also like