July 2023 2nd Paper
July 2023 2nd Paper
Mr S. TJIRASO
EXAMINER(S)
INSTRUCTIONS
1. Answer ALL the questions.
2. Read all the questions carefully before answering.
3. Number the answers clearly
PERMISSIBLE MATERIALS
1. NON-PRGRAMMABLE CALCULATOR
SECTION A: Multiple Choice Questions [20 Marks]
• Answer all the questions in the provided booklet.
• The section consists of 10 questions.
Problem Al
Study the Binary Search Tree below.
Problem A2
Given an AVL tree of size n, what would be the maximum number of steps required to find a
node k placed anywhere in the tree? [2 Marks]
E. O(e")
A. O(n)
B. O(log(n))
C. 0(1)
Problem A3
Given the BST below, what will be the value of height as returned by the function max? [2
marks]
20
1
height=max(height,, height,)+ 1
A. 1
B. 2
C. 0
D. None of the above
Problem A4
What is the depth of node 34 in the tree in Problem A3 above? (2 Marks]
A. 0
B. 1
C. 2
D. None of the above
Problem AS
What is the height of node 60 in the tree in Problem A3 above? (2 Marks]
A. 0
B. 1
C. 2
D. None of the above
Problem AG
A binary search tree is constructed by inserting the following elements in order:
60,25, 72, 15, 30, 68, 100, 13, 18 ,47, 70. How many number of left subtree nodes? (2 Marks]
A. 5
B. 7
C. 3
D. 6
Problem A7
A hash function h defined h(key)=key mod 7, with linear probing, is used to insert the keys 45,
46, 80, 56, 92, 19, 65 into a table indexed from Oto 6. What will be the location of key 19? (2
Marks]
A. 3
B. 6
C. 5
D. 4
Problem AB
Linear Probing is a conflict resolution technique in __ ? (2 Marks]
A. Hashing
B. Searching
C. Queue
D. Sorting
2
Problem A9
Which of the following statement is correct with respect to pushing data onto stack data
structure? [2 Marks)
A. Push(int data)
B. Push()
C. Pop(int data)
D. None of the above
Problem AlO
Which one of the following techniques is not used in the Binary tree? [2 Marks)
A. lnorder traversal
B. Postorder traversal
C. Randomized traversal
D. Preorder traversal
3
SECTION B: True and False Questions [10 Marks]
Problem Bl
A recursive function without a base case is equivalent to an infinite loop. [2 Marks]
Problem B2
The head of a singly-linked always points to the last node. [2 Marks]
Problem B3
Given the following recursive function;
The line below is the correct base and recurisve case(s) for the function. [2 Marks]
Problem B4
Hashing is aimed at achieving searches, deletions and insertions in O(n). [2 Marks]
Problem BS
Two distinct keys hashing to the same index is known as coalition. [2 Marks]
4
SECTION C: Structured questions [60 Marks]
• Answer all the questions in the provided booklet.
• The section consists of 5 questions.
Problem Cl
34
60
Problem C2
Explain the difference between recursion and iteration as problem-solving approaches? [4 marks]
Problem C3
Construct a BSTfor the elements: 9, 8, 12, 16, 10, using post order traversal. [10 marks]
Problem C4
Name and briefly explain any three types of AVL tree rotations [6 marks]
Problem CS
Huffman Coding is a technique of compressing data to reduce its size without losing any of the details.
Some of the benefits of compressing data are that it can be transmitted faster over the network and can
reduce "data" costs for mobile subscribers for example. Huffman Coding is one of many examples of
binary tree applications.
5
Suppose the following string is to be sent over a network
IM IM 1
5 IE 1
5 1
5 IK I
Task:
a) What is the total size of the string as it is (in bits)? [2 marks]
b) What is the average code length (ACL) of the compressed code? [4 marks]
c) Apply Huffman Coding on the string and determine the Huffman tree, the code and code length of
each character. [22 marks]