Find the In-Order Successor for a given node of a Binary Tree

  • 0

    For example for a binary tree like this:

               20                         100
         30        40               25            45
     32                23        21    22      11

    The inorder successor of node 30 is 20.

  • 0
    This post is deleted!

  • 0

    OK I thought it would be okay just to put the interview question. I didn't expect people to answer it.

    But since people post the link to the inorder successor of a Binary SEARCH Tree's link here, I have to say that the problem is not BST but Binary Tree.

    The idea is:

    • If the target node has a right child, then the answer will be the left most child for the right subtree.

    • If the target node does not have a child, then the answer will be the parent of this node.

    • If it is the last node in the Inorder Traversal, return null.

  • 0

    Sorry my bad, I will be careful next time. Thanks for posting this problem, I like it!

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.