BST Inorder Predecessor
📖 Scenario: You are working with a Binary Search Tree (BST) that stores numbers. You want to find the inorder predecessor of a given node. The inorder predecessor is the node with the largest value smaller than the given node's value.Think of the BST as a family tree sorted by age, and you want to find the closest older sibling who is younger than a specific person.
🎯 Goal: Build a TypeScript program that creates a BST, sets a target value, finds the inorder predecessor of that value in the BST, and prints the predecessor's value or null if none exists.
📋 What You'll Learn
Create a BST with the exact nodes: 20, 10, 30, 5, 15, 25, 35
Create a variable
targetValue set to 15Write a function
findInorderPredecessor that finds the inorder predecessor of targetValue in the BSTPrint the predecessor's value or
null if no predecessor exists💡 Why This Matters
🌍 Real World
Finding inorder predecessors is useful in database indexing and navigation systems where you need to find the closest smaller value to a given key.
💼 Career
Understanding BST traversal and predecessor/successor logic is important for software engineers working on search algorithms, data indexing, and optimization problems.
Progress0 / 4 steps