Question: 2 . ( 1 5 points. ) It s possible to print binary search trees ( BST s ) using a functional notation. If K

2.(15 points.) Its possible to print binary search trees (BSTs) using a functional notation. IfKis the key at the root of aBST,Lis the result of printing its left subtree, andRis the result of printing its right subtree, then we can print theBSTasK(L,R). For example, theBSTin figure14.9(a) on page 401 of Cormen can be printed ask(k(d,d),k(k(d,d),k(d,d))).
The procedure OPTIMAL-BST on page 405 returns arootmatrix that represents an optimal binary search treeOBST. Write a procedure ROOTY-PRINTthat takes such arootmatrix as its argument, and prints it using the functional notation described above. For example, if ROOTY-PRINTis given therootmatrix in figure14.10on page 406, then it must printk(k(d,d),k(k(k(d,d),d),d)). TheBSTcorresponding to this matrix is also shown in figure14.9(b) on page 401.
ROOTY-PRINTneed not print subscripts (like ). It can print ordinary digits (like 1) instead. For full credit, it must work correctly for anyrootmatrix, not just the ones in the examples. Hint: use ideas from equation 14.14 on page 404.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!