java - Efficient algorithm for finding the in-order rank of a binary tree node -
given binary tree (not binary search tree) , node in tree, efficient algorithm (in java preferably) find in-order rank of node?
an o(n)
algorithm possible traversal (either recursive or iterative). there better one? suggestion.
imagine worst case: each node has 1 left child, whole tree becomes linked list.
if given root, calculate rank need access leaf, in case costs o(n)
. o(n)
in worst case best can achieve without storing additional information in nodes.
Comments
Post a Comment