Data Structures Spring 2009

download Data Structures Spring 2009

of 2

Transcript of Data Structures Spring 2009

  • 8/6/2019 Data Structures Spring 2009

    1/2

    Data Structures Spring 2009Final ExamThere are five questions. You have 3 hours to finish the exam. All code must becommented; 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 maintainedsorted 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 themethods 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 basedon the Student ID value passed to it. [6]

    2. A min-Heap is created, using an array based implementation, through which minimum

    value can be extracted from the root node.a. Use the following values in the order given, to create this min-Heap. 15, 20, 40, 26, 30,13, 7, 12, 4, 6. Draw the resulting heap. [3]

    b. Remove the minimum value at the root and re-adjust the rest of the values to form theheap again. Redraw this resulting heap. [2]c. Write the functions(s) called for the process in Part b. [10]

    3. A pointer based Binary Search Tree is created to store integer values in each node. Afew 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 thetree. [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 usingan 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 vertexv. Note that a vertex v is not connected to vertex w if there is no path from v tow. [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 listii. Enqueue ( ) into an array based queueiii. General case Search ( ) in a sorted array based listiv. Worst case for Search ( ) in a binary search treev. ClearAll ( ) an array based unsorted listvi. ClearAll ( ) a stack implemented using a linked listvii. ClearAll ( ) a binary search treeviii. Best case for Delete ( ) from an array based binary search tree

  • 8/6/2019 Data Structures Spring 2009

    2/2

    ix. Dequeue ( ) from a heapx. Sort ( ) using a heap