Download CSL 201 Data Structures Name: End-Semester Exam

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Factorization of polynomials over finite fields wikipedia , lookup

Transcript
CSL 201 Data Structures
Name:
End-Semester Exam - 180 minutes Roll Number:
Please read the following instructions carefully
• This is a closed book, closed notes exam. Calculators are allowed. However laptops or mobile
phones are not allowed.
• Use the space provided after every question for writing your answer. You will be given additional
sheets for rough work. Please attach the additional sheet(s) along with this booklet.
• Be precise and concise in your answers.
• Include explanations, derivations, and examples when appropriate. This can fetch you partial
scores even if the final answer is incorrect.
• Please write legibly
• There are 5 questions worth a total of 50 points.
• Work efficiently. Some questions are easier than others. Try to answer the easier ones before you
get bogged down by the harder ones. Do not panic.
Question #
Max. Score
1
6
2
12
3
12
4
12
5
8
Total
50
1
Score
1
One pointers (1 x 6 = 6 points)
1.1 Bellman-Ford algorithm can compute the single source shortest path even when there are negative
cycles in the graph.
1.2 What is the lower and upper bound on the number of children of an internal node in a compressed
trie, where s is the length of the string and d is the size of the alphabet.
1.3 Binary search is as efficient on linked lists as on arrays, provided the list is doubly linked - state
true or false with justification.
1.4 How many comparisons are required to sort 11 numbers using Radix sort?
1.5 Every graph has a unique minimal spanning tree - state true or false with justification.
1.6 What is the complexity of an insertion and deletion in a red-black tree?
2
Two pointers (2 x 6 = 12 points)
2.1 What is the running time of Quicksort when all the elements in the array are the same?
2.2 Draw the frequency array and Huffman tree for the following string - dogs do not spot hot pots or cats.
2
2.3 What is the minimum number of comparisons required to sort 5 numbers?
2.4 Perform the following operations on an initially empty splay tree - insert(1), insert(10), insert(8),
insert(2), find(10), insert(3)
2.5 Consider a Tree T storing 10,000 entries. What is the worst-case height of T in the following cases
(a) T is a binary search tree
(b) T is an AVL tree
(c) T is a splay tree
(d) T is a red-black tree
2.6 List the nodes in the order they would be visited in a breadth-first search of the graph stating at
C. When choosing a node to explore next, break ties in favour of the alphabetically least. How
many directed simple cycles does this graph have?
A
B
C
D
E
F
G
H
I
J
3
3
Four pointers (4 x 3 = 12 points)
3.1 Prove the correctness of Kruskal’s algorithm for computing the minimal spanning tree of a graph.
3.2 Trace through the Floyd-Warshal algorithm to compute the transitive closure for a graph that has
nodes A, B, C, D, E, F and directed edge list (A, B), (A, C), (B, D), (B, E), (C, D), (C, E), (D, F ), (E, F )
4
3.3 Find all the occurrences of the pattern abaa in the string abcabaabcabaac by tracing through the
KMP algorithm.
5
4
Six pointers (6 x 2 = 12 points)
4.1 Say that a pattern P of length m is a circular substring of a text T of length n > m if P is a
(normal) substring of T , or if P is equal to the concatenation of a suffix of T and a prefix of T ,
that is, if there is an index 0 ≤ k < m, such that P = T [n − m + k..n − 1] + T [0..k − 1]. Give an
algorithm for determining whether P is a circular substring of T .
6
4.2 Let S be a sequence of n elements. An inversion in S is a pair of elements x and y such that x
appears before y in S but x > y. Describe an algorithm running in O(n log n) time for determining
the number of inversions in S.
7
5
Eight pointer (8 x 1 = 8 points)
5.1 Given a value N , if we want to make change for N rupees, and we have infinite supply of each
of S = {S1 , S2 , .., Sm } valued notes, What is the minimum number of notes that will add up to
N ? The order of notes does not matter. For example, if N = 4 and S = {1, 2, 3}, there are four
possible conversions: {1, 1, 1, 1}, {1, 1, 2}, {2, 2}, {1, 3}. The output of your algorithm can be {2, 2}
or {1, 3} as both require the minimum number of notes - two in this case. (8 points)
8