(10 points) Given the following algorithm:
Tree_Insert(T, e)
(1) y = NULL
(2) x = T.root()
(3) while x != NULL
(4) y = x
(5) if T.element(x) < e
(6) then x = T.leftChild(x)
(7) else x = T.rightChild(x)
(8) if y = NULL
(9) then T.insertRoot(e)
(10) else if T.element(y) < e
(11) then T.insertLeftChild(y,e)
(12) else T.insertRightChild(y,e)
- Trace the algorithm by inserting each of the following in order
(5, 7, 3, 6, 6).
- Describe what the algorithm is doing in lines (3-7), (8-12).
- Discuss why this algorithm correctly inserts into a binary tree.
- Argue the performance of this algorithm.
- Give an example of the best case and worst case performance of this
algorithm.