1.
a. Give the Preorder, Inorder and Postorder traversal sequences of the binary tree below. (9 marks)
[Figure: binary tree — root A; children B and C; B has children D and E; D has right child H; C has children F and G; G has children I and J.]
b. With the aid of a diagram, differentiate between a directed and an undirected graph. (5 marks)
c. What is the advantage of implementing a queue in the form of a circular array, instead of a linear array structure? (3.5 marks)
2.
a. Suppose STACK is allocated N = 6 memory cells and initially STACK is empty, or in other words TOP = 0. Find the output of the following module: (9 marks)
i. Set AAA = 2 and BBB = 5
ii. Call PUSH (STACK, AAA)
Call PUSH (STACK, 4)
Call PUSH (STACK, BBB + 2)
Call PUSH (STACK, 9)
Call PUSH (STACK, (AAA + BBB) * 2)
iii. Repeat while TOP != 0:
Call POP (STACK, ITEM)
Write: ITEM
[End of loop]
iv. Return
b. Using a linked list, add the following polynomials: (6 marks)
and
c. How does the implementation of a linked list differ from that of a linked queue? (1.5 marks)
3.
a. Consider the following queue where QUEUE is allocated 8 memory cells: (9 marks)
Front = 2, Rear = 5, QUEUE = __, __, London, Berlin, Rome, Paris, __, __.
Describe the queue, including Front and Rear, as the following operations take place:
i. Athens is added
ii. Two cities are deleted
iii. Madrid is added
iv. Moscow is added
v. Three cities are deleted
vi. Oslo is added
b. Consider the linear array AAA = [5:50]. Suppose Base(AAA) = 300 and w = 4 words per memory cell for AAA. Find the address of: i. AAA[15] ii. AAA[35] iii. AAA[55] (6 marks)
c. Suppose we have an array implementation of a stack, with ten items in the stack stored at data[0] through data[10]. The CAPACITY is 20. Where does the push member function place the new entry in the array? (2.5 marks)
4.
a. You have to apply linear search for an element in an array containing 5000 elements. If at the end of the search you find that the element is not present in the array, how many comparisons would you have made to search for the required element in the given list? (2 marks)
b. Convert the expression (A + B) * C + D / (E + F * G) − H + (I ^ (J * K)) from infix to postfix. (10 marks)
c. Draw the binary tree corresponding to the following algebraic expression: (5.5 marks)
5.
a. Consider the following sorted linear array. Find the element '15' using the binary search algorithm. (5 marks)
| a[0] | a[1] | a[2] | a[3] | a[4] | a[5] | a[6] |
|---|---|---|---|---|---|---|
| 3 | 10 | 15 | 20 | 35 | 40 | 60 |
b. Construct the binary tree with the following traversal sequences: (10 marks)
Pre-order: 1, 2, 4, 8, 9, 10, 11, 5, 3, 6, 7
In-order: 8, 4, 10, 9, 11, 2, 5, 1, 6, 3, 7
c. Write down the algorithm for Bubble Sort. (2.5 marks)
6. Use the graph below to answer questions 6a, 6b and 6c:
[Figure: directed graph with vertices 0–6. Arrows appear to run 0→1, 0→2, 0→3, 3→2, 3→4, 2→4, 1→5, 1→6, 6→4 and between 1 and 4 [?].]
a. Traverse the graph using Depth First Search traversal (starting vertex = 0). (9 marks)
b. What is the adjacency matrix representation of the graph? (4.5 marks)
c. What is the adjacency list representation of the graph? (4 marks)

