0% found this document useful (0 votes)
15 views

Previous Final Exam Paper

Uploaded by

ais20003ais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Previous Final Exam Paper

Uploaded by

ais20003ais
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Total Mark: 40 Duration: 120 minutes

THEORY PART

I. MULTIPLE CHOICE. (10 x 1 = 10 marks)


Encircle the letter of the correct answer that corresponds to the given statement.

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.

3. Which of the statements below about Linked List is TRUE?


A. The nodes of linked list are linked to one another by means of an edge.
B. Singly linked list (SLL) can traverse in both forward and backward directions.
C. Every node in a doubly linked list (DLL) has two fields.
D. In a circular linked list (CLL), all nodes are linked in a continuous circle without using
NULL.

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

6. How many subtrees can a node in a binary tree has?


A. Zero (0)
B. One (1)
C. Two (2)
D. All of the choices

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).

II. SHORT ANSWER (COMPUTATION). (5 X 2 = 10 marks)


Answer all the questions below. Perform the required operations and show your solution in
the space provided. You may also use the attach paper for rough work.

11. The two-dimensional array marks is represented in the table below.


85 78 90
67 92 70

a. Write the order of elements using column-major representation. (1 mark)

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")

Total Step Count


Name of the complexity

13. Graph Application. Answer all the questions based on the graph given below.

A. How many vertices are there in the graph? (0.5 mark)

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)

Steps Write the letter Description


of correct
description
here
1. Define the A. Create a head pointer and initially set it to
Node Structure. ‘None’. This head will point to the first
node of the linked list.
2. Initialize the B. Start from the head. While the current
linked-list. node is not ‘None’, print (or process) the
node's data and move to the next node
3. Add Node to C. Each node should have at least two parts:
the List at the one part to store data and another to store
end. the reference to the next node.

4. Traverse the D. Create a new node with the given value.


list. If the list is empty (head is ‘None’), set the
head to point to the new node.
If the list is not empty, traverse the list to
find the last node and set its next
reference to the new node

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)

K 1234 4321 1122 4237


K2 1522756 18671041 1258884 17952169
Hash Key

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

A. Write the correct answer on the following tree application questions:

1. What are the terminal nodes? (0.5 mark)

2. what is the height of the tree? (0.5 mark)

B. Represent the binary tree as an array. (1 mark)

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

B. Answer the questions based on the given stack. (1 mark)

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

B. Answer the questions below using the given queue. (1 mark)


Queue
Index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Element M R S T
Front Rear
Algorithm Questions
Enqueue (“A”) After executing the algorithm.
Enqueue (“B”) a. what is the index value of front?
Dequeue()
Dequeue()
b. What is the index value of the rear?

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

Write the values after first swapping

Write the values after second swapping

B. Explain briefly the process of quick sort. (2 marks)

Page 14 of 16
Rough Work

Page 15 of 16
Rough Work

Page 16 of 16

You might also like