January 09, 2025 |5.2K Views

    Find next right node of a given key

      Share   Like
    Description
    Discussion

    Given a Binary tree and a key in the binary tree, find the node right to the given key. If there is no node on right side, then return NULL. Expected time complexity is O(n) where n is the number of nodes in the given binary tree.

    For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 and 5 is NULL.

                     10
                  /      \
             2         6
              /   \         \ 
        8      4          5

    Find next right node of a given key: https://www.geeksforgeeks.org/find-next-right-node-of-a-given-key/