BST Insert Operation
📖 Scenario: You are building a simple phone book app that stores contacts in a Binary Search Tree (BST). Each contact has a unique phone number. You want to add new contacts in the correct position in the BST so that searching is fast.
🎯 Goal: Build a TypeScript program that creates a BST node class, sets up an initial BST, inserts a new contact with a phone number into the BST, and prints the BST in order.
📋 What You'll Learn
Create a
Node class with phoneNumber, left, and right propertiesCreate a variable
root that is the root node of the BST with phone number 50Create a variable
newPhoneNumber with the value 30Write a function
insertNode that inserts a new phone number into the BST correctlyPrint the BST phone numbers in ascending order after insertion
💡 Why This Matters
🌍 Real World
Phone books, contact lists, and databases use BSTs to store and quickly find data.
💼 Career
Understanding BST insertions is important for software engineers working with data structures and algorithms.
Progress0 / 4 steps