Previous Final Exam Paper
Previous Final Exam Paper
THEORY PART
1. What kind of algorithm is applied to games, like soduku and rat in a maze?
A. Brute-force
B. Greedy
C. Backtracking
D. Divide and conquer
2. Which of the following statements about array and linear list is NOT true?
A. Both array and linear list organize elements sequentially.
B. The index of both array and linear list starts at zero (0).
C. Both array and linear list can store elements of same data types.
D. Both array and linear list have fixed sizes.
4. What is the first step to push an element into a stack provided there is still an available
space for the new element?
A. Subtract minus 1 from the top index (top--) and put the new element to the top.
B. Add plus 1 to the top index (top++) and put the new element to the top.
C. Remove current element from top and replace it with new element.
D. Remove the first element because new element is automatically added at the first
position.
Page 3 of 16
5. What are the special markers of a queue data structure? (SELECT TWO)
A. tail
B. front
C. rear
D. head
7. You are looking for your room assignment for the data structure final
exam class in the new building. The building has two entrances, one from
the right of the hallway, the other from the left. You decided to take the
left entrance, and then you found out that your room assignment is just
beside the right entrance. What is the case of time-complexity presented
in this scenario?
A. Best case
B. Average case
C. Worst case
D. All of the choices
8. What do you call the process of rearranging the contents of a list in a specific order?
A. hashing
B. searching
C. sorting
D. chaining
Page 4 of 16
9. Which of the statements below about Depth-First Search Graph Traversal is TRUE?
(SELECT TWO)
A. It uses stacks in its implementation.
B. It uses queue in its implementation.
C. It uses the idea of backtracking.
D. It traverses the graph in a breadth ward motion.
10. Which of the following statements is TRUE about binary search technique?
A. Searched element is to be compared to the key present in the first position.
B. Elements to be searched must be sorted.
C. It is iterative in nature.
D. Time complexity is O(n).
b. Using row major representation, what is the element in the marks[0][2] index?
(0.5 mark)
c. Using row major representation, what is the index of element 78? (0.5 mark)
Page 5 of 16
12. Identify and compute the time complexity of the codes given below.
Algorithm Step Count
#final exam
n = int(input("enter a value:"))
for x in range(n):
print("Data Structure")
for y in range(x):
print(x*y)
print(x+y)
print("UTAS-Shinas")
print("Final Exam")
print("Algorithms")
13. Graph Application. Answer all the questions based on the graph given below.
Page 6 of 16
B. How many edges are there in the graph? (0.5 mark)
C. Draw the minimum spanning tree (MST) from this graph given A as the source. (1 mark)
Page 7 of 16
14. The algorithm to create a singly linked list is presented below. Match the steps with its
detailed description by writing the letter of the description opposite the step. (2 marks)
Page 8 of 16
15. Draw the binary search tree of the values given below. (2 marks)
40 75 -3 7 -5 18 24 -1 46 -2
Page 9 of 16
III. LONG ANSWER (COMPUTATION). (5 X 4 = 20 marks)
Answer all the questions below. Perform the required operations and show your solution in
the space provided. You may also use the attached paper for rough work.
16. A company wants to store the records of its staff in a two-digit memory address. Using mid-
square method, give the value of the hash key from the values provided in the table below.
(2 marks)
From the values computed, is there a hash-collision detected? Explain your answer.
(2 marks)
Page 10 of 16
17. Answer the following questions on tree application.
R T
A S H
X P
C. Give the preorder and postorder traversal of the binary tree. (2 marks)
Preorder Traversal Postorder traversal
Page 11 of 16
18. Stack Application.
A. Evaluate the postfix expression below: (3 marks)
4 2 1+* 3 –
Element Stack Operation Stack
4
2
1
+
*
3
–
Stack
Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Element M N Q R F
Top
Algorithm Questions
Pop() After executing the algorithm.
Pop() a. what is the index value of the top?
for x in range(3):
push (“A”)
b. Write all the elements in the stack.
push(“D”)
Page 12 of 16
19. Queue Application.
A. Sort the following unsorted list of integers using radix sort. (3 marks)
15 90 42 37 39 44 96 102 65
Queue 0 Queue 1 Queue 2 Queue 3 Queue 4 Queue 5 Queue 6 Queue 7 Queue 8 Queue 9
Queue 0 Queue 1 Queue 2 Queue 3 Queue 4 Queue 5 Queue 6 Queue 7 Queue 8 Queue 9
Queue 0 Queue 1 Queue 2 Queue 3 Queue 4 Queue 5 Queue 6 Queue 7 Queue 8 Queue 9
Page 13 of 16
20. Quick sort application.
A. Sort the unsorted list of numbers using the quick sort technique using the value 13 as
pivot.
(2marks)
2 15 14 13 12 7
Pivot
Page 14 of 16
Rough Work
Page 15 of 16
Rough Work
Page 16 of 16