Binary Tree - 71: Check if given Binary Tree is BST

preview_player
Показать описание
Solution:
- We traverse the binary tree in inorder manner
- We take a global variable 'prev'.
- Now whenever we're traversing any node, we check node value with previous node value
- If current node value is less than previous value, we return false, else we keep on checking.
- We check this for all nodes in tree

Time Complexity: O(n)
Space Complexity: O(1)

Do Watch video for more info

CHECK OUT CODING SIMPLIFIED

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 200+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★
Рекомендации по теме
Комментарии
Автор

Plz make a series on recursion problems as well.

divanshmahajan
Автор

why are we checking !isBST and returning false. Can't we do isBST and return true?

rahulsaxena
Автор

in code you write node.data < prev.data what about prev.data > node.data??

ABHISHEKAnand-utfq
Автор

Really enjoyed learning part of BST from you

randomperson
Автор

I got only false and I have no idea where did I go wrong.

RizaHariati
Автор

SIR plz make video on searching, sorting technique using java

rohitpawar
Автор

Most Underrated channel
Great explanation bro.

uditkhanna
Автор

Hey. First of all great content again.
Secondly don't you think that the condition should have been prev.data>=node.data,
since binary search tree does not allows duplicate values.
In case of a tree with all one's the the output coming is true where as it's not a BST.
Just a suggestion that's it bro.

uditkhanna
welcome to shbcf.ru