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

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -