Reference no: EM133339257
Question: Study the following recursive pseudocode algorithm.
FUNCTION Recursive(Num1, Num2 : INTEGER) RETURNS INTEGER
IF Num1 > Num2 THEN
RETURN 10 ELSE
IF Num1 = Num2 THEN
RETURN Num1 ELSE
RETURN Num1 + Recursive(Num1 * 2, Num2)
ENDIF
ENDIF
ENDFUNCTION
(a) The function is called as follows:
Recursive(1, 15)
Dry run the function and complete the trace table. Give the final return value.
Trace table:
Function call
|
Num1
|
Num2
|
Return value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Final return value
Working
(b) Rewrite the function Recursion() in pseudocode, using an iterative algorithm.
2. What is a data structure?
b) What do you understand by the terms: height of a binary tree and a full binary tree?
c) State two main factors that determine the choice of a data structure for a program ii.)a) Make a BST for the following sequence of numbers. 45, 36, 76, 23, 89, 115, 98, 39, 41, 56, 69, 48
b) Traverse the tree in Preorder, Inorder and Postorder.
c) Redraw the BST above after deleting the element 45
iii.) a)A stack operation is given as S.opx(p), where S is a stack, "opx" the operation and "p" the parameter to use.
Show the contents of the stack S after each of the following operations, a.1-a.4have been performed
S.push(2)
S.push(4)
S.push(S.pop()+S.peek())
S.push(S.pop()-S.pop())
b) Using the hash function h(key) = key modulo 9, insert in the order given the keys 5, 29, 20, 0, 27, and 18 into a hash coded table of size 9. Use linear probing to handle collisions.