Question: 3. Consider a binary search tree used to store integers with methods isEmpty(t), left(t), right(t) and root(t), to return whether the tree t, is empty,

3. Consider a binary search tree used to store integers with methods isEmpty(t), left(t), right(t) and root(t), to return whether the tree t, is empty, the left child tree, the right child tree and the integer value stored at the root respectively. Write a recursive function sum rec(tree) to calculate and return the sum of all integers stored in the tree. [5 marks] A Queue ADT has, for a queue q, methods q.enqueue (val) and q. dequeue () to enqueue a value val in the queue and to dequeue and return a value from the queue respectively. It also has a constructor which can be invoked with the commmand new Queue () to create and return a new empty queue. Write the pseudocode for a non-recursive function sum nonrec(tree), to calcu- late and return the sum of all integers stored in the tree. (10 marks)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
