Skip to content

Latest commit

 

History

History
83 lines (51 loc) · 1.24 KB

README.md

File metadata and controls

83 lines (51 loc) · 1.24 KB

Insert Node in Binary Search Tree (BST)

C++ implementation of inserting a node into a Binary Search Tree (BST) with inorder traversal for verification.


📘 Overview

This project demonstrates how to insert a value into a Binary Search Tree using C++.
It includes a simple BST node structure, insertion logic, and traversal to verify correctness.


🧠 Concepts Covered

  • Binary Search Tree (BST)
  • Recursion
  • Tree traversal (Inorder)
  • Struct usage in C++

📂 Project Structure

INSERT_NODE_IN_BST ├── main.cpp └── README.md


⚙️ Implementation Details

The program includes:

  • A Node structure representing BST nodes
  • A recursive function to insert a node
  • Inorder traversal to display sorted values

▶️ How to Compile and Run

Compile

g++ main.cpp -o bst

Run:

./bst

⏱ Complexity

Insertion in BST:

Average Time Complexity: O(log n)

Worst Case: O(n)

🛠 Language Used C++


Example Output

Before insertion: 20 30 40 50 60 70 80

After inserting 65: 20 30 40 50 60 65 70 80


Problem explanation

A Binary Search Tree maintains elements in sorted order. Insertion places the new value in the correct position based on BST properties.