Closed ywxktc closed 4 years ago
Thanks for pointing out this issue.
Yes, we should avoid calling PARENT
in TREE-PREDECESSOR
and we should aim for a O(lg n) algorithm to find the predecessor since we're given a BST.
It seems that your pseudocode is not correct. I've updated the solution here and provided examples in the .cpp code.
Hope this helps. Thanks.
The worst-case running time of
TREE-PREDECESSOR
is O(lg(n) * lg(n)) since the 7th line could be executed O(lg(n)) times and the running time ofPARENT
is O(lg(n)).I rewrite the
TREE-PREDECESSOR
.