Professional Documents
Culture Documents
Final Exam
There are five questions. You have 3 hours to finish the exam. All code must be
commented; otherwise it may not be checked. Code written in pencil cannot be re-
checked. Ensure you cover general and boundary cases for your algorithms. Good luck!
1. A doubly linked circular list is used to maintain student records. The list is maintained
sorted on Student ID, which is a unique integer. In addition, Student Name (as a sting)
and Student CGPA (as a float) are also stored. The list is maintained using the First
pointer.
a. Give the declaration for the relevant class(es) for this data structure. List all the
methods of the class(es) completely with no. of arguments, their types, and return values.
You do not need to define the methods. [4]
b. Define the delete( ) function for this list, which deletes the student from the list based
on the Student ID value passed to it. [6]
3. A pointer based Binary Search Tree is created to store integer values in each node. A
few such values are then entered to build the tree so that the tree remains complete.
a. Write function(s) to input an integer ‘n’ and print only the values at level ‘n’ of the
tree. [15]
b. Write a recursive version of the destructor for this BST. [10]
4. An undirected graph has exactly 20 vertices, labeled from 0 till 19 and is stored using
an adjacency matrix. Write the class method: void printUnconnectedVertices (int vertex);
which inputs a vertex number ‘v’ and prints all the vertices not connected to this vertex
‘v’. Note that a vertex ‘v’ is not connected to vertex ‘w’ if there is no path from ‘v’ to
‘w’. [20]
5. What is the order of the following operations, given each data structure has N values:
[10]
i. General case for Insert ( ) into a sorted doubly linked list
ii. Enqueue ( ) into an array based queue
iii. General case Search ( ) in a sorted array based list
iv. Worst case for Search ( ) in a binary search tree
v. ClearAll ( ) an array based unsorted list
vi. ClearAll ( ) a stack implemented using a linked list
vii. ClearAll ( ) a binary search tree
viii. Best case for Delete ( ) from an array based binary search tree
ix. Dequeue ( ) from a heap
x. Sort ( ) using a heap