VOOZH about

URL: https://www.geeksforgeeks.org/dsa/check-array-represents-inorder-binary-search-tree-not/

⇱ Check if an array represents Inorder of Binary Search tree or not - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Check if an array represents Inorder of Binary Search tree or not

Last Updated : 5 May, 2026

Given an array arr[] of size n containing unique elements, check whether it represents the inorder traversal of a Binary Search Tree (BST) or not.

Examples:

Input: arr[] = { 19, 23, 25, 30, 45 }
Output: true
Explaination: Given array is inorder traversal for the following tree:

👁 2056957867

Input : arr[] = { 19, 23, 30, 25, 45 }
Output : false
Explanation: The array is not in increasing order (since 30 > 25), so it cannot represent the inorder traversal of a Binary Search Tree (BST).

The idea is to use the fundamental property of BST: Inorder traversal of a Binary Search Tree always gives a sorted sequence. So, simply check whether the given array is sorted in increasing order or not.


Output
true
Comment
Article Tags: