Inorder Successor of BST

Problem

Concept

We can find the next inorder successor by performing an inorder traversal. But that is not an efficient way. Why? Because we are not using any properties of the BST to find out what is the next inorder successor.

We need to understand where the successor could appear if you want to use BST properties.

Using BST properties, if we want to find the inorder successor

Algorithm

Solution

circle-info

Time Complexity:

n -> Number of nodes in BST

  • Best Case: O(log n)

  • Worse Case: O(n), skewed BST

circle-check

Space Complexity: `O(1)`

Last updated