Professional Documents
Culture Documents
DSA - Final Exam - 2010
DSA - Final Exam - 2010
DSA - Final Exam - 2010
Id Number: ______________________________________
General Instructions
1. Before you start, please first check that this exam booklet has 4 pages and three
sections:
Part I: Multiple Choices (20 points)
Part II: Workout (30 points)
2. Read each instructions and questions carefully and try to attempt all of them.
3. Give your answer on the spaces provided.
4. Be honest to work your own and be reminded that there is no excuse for cheating!
1
Part I: Multiple Choice (20 points)
1. In a single linked list each node contains minimum of two fields. One field is data field to
store the data second field is?
2. Consider an implementation of unsorted singly linked list with a start pointer only. Given
the representation, which of the following operation can be implemented in O(1) time? a
a) Insertion at the front of the linked list
b) Insertion at the end of the linked list
c) Deletion of the front node of the linked list
d) Deletion of the last node of the linked list
e) a & c
4. Assume you want to build a task reminder for a smartphone that keeps track of events
you schedule and periodically checks the next event to sound an alarm to remind you of
the next thing you need to do. What data structure should you use?
a) List d) Queue
b) Array e) Priority Queue
c) Stack
6. Which of the following real world scenarios would you associate with a stack data
structure?
a) Placing up of chairs one above the other
b) People standing in a line to be serviced at a counter
c) Offer services based on the priority of the customer
d) All of the mentioned
2
7. What does ‘stack underflow’ refer to?
a) accessing item from an undefined stack
b) adding items to a full stack
c) removing items from an empty stack
d) index out of bounds exception
9. What is the specialty about the in-order traversal of a binary search tree?
a) It traverses in a non-increasing order
b) It traverses in an increasing order
c) It traverses in a random fashion
d) None of the mentioned
3
Part II: Workout (30 points)
1. Consider the linked list of integers represented by the following diagram and answer the
following questions.
a) Draw a diagram of the above list after the following lines of code have been
executed.
Node* prev = head->next;
Node* nodeToInsert = new Node;
nodeToInsert->item = 4;
nodeToInsert->next = prev->next;
prev->next = nodeToInsert;
b) In addition to the code above, assume the following code executes. Draw a diagram
of the list after this code executes as well.
prev = prev->next;
prev = prev->next;
Node* curr = prev->next;
prev->next = curr->next;
delete curr;
curr = NULL;
2. Briefly explain what a binary search tree (BST) is, listing its properties. Is the following
binary tree a BST or not, and why?
4
3. Run the operations below based on the following binary search tree. Explain the
necessary steps clearly and re-draw what the tree will look like after each operation.
a) Insert (1)
b) Find(120)
c) Delete (42)
d) Delete (37)
5. Consider the binary tree shown below. For each of the traversals listed, give the order in
which the nodes are visited.
5
Answer
Preorder
Inorder
Postorder