Validate if Tree is BST
📖 Scenario: You are working with a simple binary tree structure in C++. You want to check if this tree follows the rules of a Binary Search Tree (BST). A BST is a tree where for every node, all nodes in the left subtree have smaller values, and all nodes in the right subtree have larger values.
🎯 Goal: Build a program that creates a binary tree, sets up a helper function to check BST rules, and then prints whether the tree is a valid BST or not.
📋 What You'll Learn
Create a binary tree with exactly 3 nodes with values 10, 5, and 15
Add a helper function to check if the tree is a BST using recursion
Use the helper function to determine if the tree is a BST
Print "BST" if the tree is valid, otherwise print "Not BST"
💡 Why This Matters
🌍 Real World
Checking if a tree is a BST is important in databases and search algorithms where data needs to be organized for fast lookup.
💼 Career
Understanding BST validation helps in roles involving data structures, algorithm design, and software engineering where tree data is common.
Progress0 / 4 steps