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

javascript - Can Piwik report referrer in real time? -

asp.net - Google Drive Access: At least one client secrets (Installed or Web) should be set -

excel vba add hyperlink to shape in group -