COL106 Major Subjective
COL106 Major Subjective
Please use only pens while answering subjective questions. Do not use a pencil. The exam is
closed book, closed notes and no browsing on the Internet. If we find any form of
collaboration with any other person during the course of exam, or even if we find you typing
on your computer or phone, it will result in a straight zero on the exam – no exceptions. Your
video and speaker must be on at all times, and mic must be off. At the end of the time, upload
the answers in Gradescope in the next 20 mins, as per Piazza instructions. No pen should be
touched during this time and the video should continue to be on.
1. [5 marks] Draw an AVL tree that satisfies all the following three conditions:
(a) The tree has exactly 11 nodes numbered 1 to 11.
(b) There are no pair of nodes that, if extracted one after the other, will cause the height
decrease by 1.
(c) There is no key whose insertion will increase the height by 1.
2. [17 marks] In this problem, we define and analyze a new data structure called the BSHeap,
short for a binary search heap. It is a special kind of binary search tree which also has the
property of a heap. Each item in a BSHeap is a tuple of two values i.e. xi = (ki, pi) where ki is
a key and pi is a priority. A BSHeap is a binary search tree on the keys of the items and
maintains the min-heap order property on the priorities i.e. the priority value of a node is less
than the priority value of any children it may have. Note that BSHeap does not have to have
the structural property of a heap i.e., it may not be a complete binary tree.
(a) [3 marks] Construct a valid BSHeap on this set. (you need not show any steps, just the final
answer): {(5,4), (35, 11), (4,7), (20,1), (28, 8), (18,3), (30,2), (19,12), (25,5), (22, 9)}
(b) [3 marks] Perform the “deleteMin” operation on this. That is, remove the node with the
smallest priority. You need not show the steps, just the final answer.
(c) [7 marks] Write the pseudo-code for the deleteMin operation. You can assume access to
any algorithm/methods discussed in class.
(d) [4 marks] What are the best case and worst case time complexities of deleteMin? Exactly
when would the worst and best cases occur.
(a) [2 marks] Let T(n) denote the worst case number of comparisons (A[0] > A[1]) made for an
input array of n numbers. Give a recurrence relation for T(n).
(b). [4 marks] Solve the recurrence – give a tight (Θ) asymptotic bound for T(n). You are not
allowed to use Master theorem (if you know it).
5. [7 marks] Consider the skip list data-structure where the probability that an element moves to
the next level is p (instead of 0.5). What is the expected running time for searching an element?
Give reasons. You can use order notation, but dependence of the running time on p should be
clearly mentioned.
6. [7 marks] You are given an array containing N numbers. Each number lies in the range [0, N2].
Give an O(N) time algorithm (write pseudo-code) to sort them in increasing order. Explain.
7. [7 marks] You are given an undirected graph G in the adjacency list data-structure. Each edge
e also has a length le which is given to you. You are also given a minimum spanning tree T of
G (again in the adjacency list data-structure). Suppose we increase the length of an edge e from
le to me (note that the length of only one edge is changing, lengths of rest of the edges are
staying unchanged). Give a linear time algorithm (write pseudo-code) to compute the new
minimum spanning tree.
8. [8 marks] You are given an undirected graph G in the adjacency list data-structure. Give an
efficient algorithm (write pseudo-code) to find the shortest cycle in the graph (length of a cycle
is defined as the number of edges in it). Give reasons why your algorithm is correct and state
the running time. Your algorithm should be as efficient as possible.
9. [10 marks] Technical comparisons between two data structures/algorithms. Note, please be
brief and use technical reasons. E.g., easy to program/easy to understand are not valid technical
comparisons. Space complexity, time complexity, or a specific operation being more efficient,
and other such technical comparisons are valid.
a. State one benefit of adjacency matrix over adjacency list for directed graphs.
b. State one benefit of adjacency list over adjacency matrix for directed graphs.
c. State one benefit of doubly linked list over singly linked list.
d. State one benefit of singly linked list over array.
e. State one benefit of heapsort over mergesort.