Programming Techniques Homework 5 Recursion
Programming Techniques Homework 5 Recursion
Homework 5 Recursion
1. Give three properties of a recursive algorithm. [3]
(b) Write pseudocode statements to call the routine with a parameter 5 and print the
output.
[2]
1
Homework 5 Recursion
Unit 11 Programming Techniques
John
Alan Peggy
The binary tree may be represented using three one-dimensional arrays named left, name,
right.
Index left name right
[0] 2 John 1
[1] 5 Peggy 4
[2] -1 Alan 3
[3] -1 Chris -1
[4] -1 Sue -1
[5] -1 Ken -1
The procedure below describes a type of tree traversal that can be carried out on the tree.
procedure traverse (pos)
if left(pos) != -1 then traverse (left(pos))
if right(pos) != -1 then traverse (right (pos))
print name(pos)
endprocedure
Using the table below trace the execution of the program when it is called with
traverse(0). [5]
pos output
Total 15 marks
2