Professional Documents
Culture Documents
CE221 MT Questions
CE221 MT Questions
Instructions
• Please write your solutions in the spaces provided on the exam sheets. Make sure your
solutions are neat and clearly marked. You may use the blank areas of the exam pages for
scratch work. Please do not use any additional scratch paper.
• Simplicity and clarity of solutions do count. You may get as few as zero points for a
problem if your solution is far more complicated than necessary, or if we cannot understand
your solution.
Problem 1 2 3 4 5 Total
Max. Points 20 15 20 25 20 100
Score
Good Luck
1/4
Questions
2/4
Problem 3) Efficiency is the major concern! [20 pts.]
In this question, you are to design an efficient algorithm that takes an array of
positive integers named A with size n, and return the maximum value of A[j]-A[i],
with n > j ≥ i ≥ 0. Your algorithm should run in O (n). You can assume that the
function prototype for your algorithm is given by int maxDiff(int A[],int n).
Hint: Try to beat the maximum found while scanning the array. At any point in the
algorithm, while j scans the array, i refers to the position of the minimum value seen
so far.
Solution:
4.2 [10 pts.] Show the result of deleting the root of the binary search tree formed
after the insertions performed above (i.e., perform the deletion in the tree obtained
in 4.1).
Solution:
3/4
Problem 5) Expression Trees and Tree Traversals [20 pts.]
Give the inorder, postorder, and preorder expressions corresponding to the
expression tree shown below.
* e
* +
a b c d
Solution:
Good Luck
4/4