Python program to check if an array represents Inorder of Binary Search tree or not
Description:
Given array represents Inorder of BST if the array is sorted elsenot.
Program:
defisSorted(arr):if (all(arr[i] < arr[i+1] for i in range(len(arr)-1))):
returnTrueelse:
returnFalseif __name__ == '__main__':
arr = [19, 23, 25, 30, 45]
if isSorted(arr):
print("Array represents Inorder of Binary Search tree")
else:
print("Array doesnot represent Inorder of Binary Search tree")
output:
Array represents Inorder of Binary Search tree
Comments