DSA - Final Exam - 2010

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Addis Ababa Science and Technology University

Department of Software Engineering


Data Structure and Algorithm

Final Exam (50%)

2017/18 Academic Year – First Semester

Full Name: ______________________________________

Id Number: ______________________________________

Time allowed: 2:30 hours

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!

Wishing you Success in Your Exams!

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?

a) Pointer to character c) Pointer to node


b) Pointer to integer d) Node

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

3. Which one of the following is an application of Queue Data Structure?


a) When a resource is shared among multiple consumers like
b) Task scheduler in multiprocessing system
c) Telephone calls in a busy environment
d) Simulation of a waiting line of persons for a bus
e) All

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

8. Which of the following is false about a binary search tree?


a) The left child is always lesser than its parent
b) The right child is always greater than its parent
c) The left and right sub-trees should also be binary search trees
d) None of the mentioned

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

10. Which of the following is true?


a) A graph may contain no edges and many vertices
b) A graph may contain many edges and no vertices
c) A graph may contain no edges and no vertices
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)

4. Provide brief descriptions of Depth-First-Search (DFS) and Breadth-First-Search (BFS)


algorithms.

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

6. Consider the following graph and work on the following questions.

a) What kind of graph is it?


b) Draw its adjacency matrix
c) Draw its adjacency list

You might also like