• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
July 18, 2024 |4.3K 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/