Visualize BST validation step by step. Watch the min/max bounds narrow at each recursion level to catch violations that a simple parent-child check would miss.
About this algorithm
Validation checks that a binary tree really follows the search tree rule: every value in a left subtree is smaller than the node above it, and every value in a right subtree is larger, all the way up, not only for the direct parent. The usual method passes an allowed range down the tree and checks each node against it. This is LeetCode 98.
Use it when a tree came from outside your own insert code, such as a file, an API or a hand-built test, and every later search would silently give wrong answers if the rule were broken. Search, insert, lowest common ancestor and k-th smallest all trust the rule without checking it, so this is the page that earns that trust. The range method stops at the first bad node. An in-order traversal that checks each value is larger than the last one works equally well and is often shorter to write; see the in-order traversal page.
The root may hold any value: its range is minus infinity to plus infinity.
The value must be strictly greater than the lower bound and strictly smaller than the upper bound. If it is not, the tree is invalid and you can stop.
The left child keeps the node's lower bound and gets the node's own value as its new upper bound. The right child gets the node's value as its new lower bound and keeps the upper bound. Each bound is the tightest limit set by any ancestor so far.
A missing child is always valid. When every node has passed, the whole tree is a valid search tree.
The page checks its seven-node tree in pre-order. 20 sits in (minus infinity, plus infinity). 10 must sit in (minus infinity, 20), and 5 in (minus infinity, 10). 15 must sit in (10, 20): above 10 because it is right of 10, and below 20 because it is left of 20. On the right side, 30 sits in (20, plus infinity), 25 in (20, 30) and 35 in (30, plus infinity). All seven pass, so the page reports a valid tree. It always will here, because every node on this page arrives through BST insert. To see a failure, picture 15 replaced by 22. A check of each node against its parent alone passes, since 22 is larger than 10. The range check fails, because 22 is outside (10, 20): it sits in the left subtree of 20 while being larger than 20.
The bounds are strict, so a duplicate fails. If your tree allows duplicates on one side, make that side of the check non-strict. In languages with fixed-size integers, starting the bounds at the smallest and largest int breaks when a node holds exactly that value; use null for "no bound yet", or a wider type.
Time: a valid tree has every node checked once against two numbers, so the work grows with N; an invalid one can stop sooner. Space: the recursion holds one frame per level of the current path, which is the height H: about log N for a balanced tree and N for a chain.