Skip to content
ExamHope Logo

examhope

Primary Menu
  • Digital Logic
    • Arithmetic Operations
    • Asynchronous/Ripple Counters
    • Basic Gates
    • Boolean Algebraic Theorems
    • Codes
  • Data Structures
    • Binary Heaps
    • Binary Search
    • Binary Search Trees
    • Binary Tree
    • Binary Tree Sort
    • Bipartite Graphs
    • Complete Graph
  • Theory of Computation
    • Finite Automata
    • Finite Automaton First Example
  • Current Affairs
    • Sports News
    • Tech News
    • Bollywood News
    • Daily News
  • Database
  • Computer Network
  • Computer Organization and Architecture
  • C Language
  • Operating Systems
  • Software Engineering
  • Theory of Computation
  • About us
  • Contact Us
  • Privacy Policy
  • DMCA Policy
  • Terms and Conditions
  • Home
  • IT
  • Data Structures
  • Binary Search Trees — Data Structures
  • Binary Search Trees
  • Data Structures

Binary Search Trees — Data Structures

examhopeinfo@gmail.com November 12, 2025 4 minutes read
Binary Search Trees

Binary Search Trees

🌱 What Is a Binary Search Tree?

A Binary Search Tree, or BST, is a special type of binary tree that keeps its elements in a sorted order.
This makes searching, inserting, and deleting data very fast — much faster than in an unsorted tree or a list.

But what makes it special?

It follows a simple rule at every node:

👉 Left child < Parent < Right child

That means:

  • Every value in the left subtree is smaller than the node’s value.
  • Every value in the right subtree is larger than the node’s value.

🌳 Let’s Look at an Example

Imagine this Binary Search Tree:

        50
       /  \
     30    70
    / \    / \
  20  40  60  80

Here’s how it follows the BST rule:

  • The root node is 50.
  • Everything left of 50 (30, 20, 40) is smaller than 50.
  • Everything right of 50 (70, 60, 80) is greater than 50.
  • If you pick 30, its left child 20 is smaller, and its right child 40 is larger.
  • The same goes for 70 — its left child 60 < 70, and its right child 80 > 70.

It’s like a perfectly balanced see-saw of numbers!


🌿 Why Is It Called a “Search” Tree?

Because it makes searching lightning fast ⚡

Let’s say you want to find 40 in the above tree.

  • Start at the root (50).
  • Since 40 < 50, go left.
  • Now you’re at 30.
  • Since 40 > 30, go right.
  • You find 40! 🎯

You didn’t need to look through every element — just followed the logical path.
This is much faster than searching line by line through an unsorted list.


🌸 Everyday Analogy

Think of it like searching a word in a dictionary:
You don’t start from the first page every time.
If you’re looking for “Mango,” you flip somewhere around the middle — maybe near “L.”
Then, if “Mango” is further ahead, you go right. If it’s before “L,” you go left.

That’s exactly how a Binary Search Tree behaves — divide and conquer!


🌺 Basic Operations in a BST

Let’s quickly go over what we can do with a BST:

1. Search

  • Start from the root.
  • Compare the value you’re looking for with the current node.
  • Move left if it’s smaller, or right if it’s larger.
  • Continue until you find it or reach a NULL (meaning it doesn’t exist).

2. Insertion

  • Start at the root.
  • Compare the new value with the current node.
  • Go left if it’s smaller, right if it’s larger.
  • Place the new node when you find an empty spot.

Example:
Insert 65 in our tree:

        50
       /  \
     30    70
    / \    / \
  20  40  60  80
           \
            65

Since 65 > 60 but < 70, it fits as the right child of 60.

3. Deletion

There are three possible cases when deleting a node:

  • The node is a leaf (no children) → just remove it.
  • The node has one child → replace it with its child.
  • The node has two children → replace it with its inorder successor (the smallest value in the right subtree).

Deletion keeps the BST rules intact.


🌻 Traversing a BST

Tree traversal means visiting every node in some order.
The three common methods are:

  1. Inorder Traversal (Left → Root → Right)
    Gives elements in sorted order!
    Example output for our tree: 20, 30, 40, 50, 60, 70, 80
  2. Preorder Traversal (Root → Left → Right)
    Useful for creating a copy of the tree.
  3. Postorder Traversal (Left → Right → Root)
    Useful for deleting or freeing nodes.

🌼 Diagram – Binary Search Tree Structure

           50
         /    \
       30      70
      / \      / \
    20  40   60  80
  • Left subtree (30, 20, 40) < 50
  • Right subtree (70, 60, 80) > 50
    That’s the core rule of a BST.

🌻 Advantages of BST

✅ Fast Searching – Average time complexity is O(log n)
✅ Efficient Insertion/Deletion – Keeps data sorted automatically
✅ Easy to Traverse – Especially for sorted output using inorder traversal
✅ Dynamic Size – Can grow or shrink as needed (unlike arrays)


🌸 A Word of Caution

BSTs work best when they’re balanced.
If you keep inserting values in increasing order (like 10, 20, 30, 40…),
the tree will lean to one side — becoming more like a linked list.
This makes it slower (O(n) time).

To fix this, we use balanced BSTs like:

  • AVL Trees
  • Red-Black Trees

But that’s a story for another day. 🌱


🌷 Summary

ConceptDescription
DefinitionA binary tree where left < root < right
PurposeFast searching, inserting, and deleting
RuleLeft child smaller, right child larger
Traversal (Inorder)Gives sorted elements
ApplicationsDatabases, searching, indexing, symbol tables

About the Author

examhopeinfo@gmail.com

Administrator

Visit Website View All Posts

Post navigation

Previous: Representing Lists as Binary Trees — Data Structures
Next: Heap — Data Structures

Related News

Linked Representation
  • Linked Representation of a Graph
  • Data Structures

Linked Representation of a Graph

examhopeinfo@gmail.com November 14, 2025 0
Path Matrix
  • Path Matrix
  • Data Structures

Path Matrix

examhopeinfo@gmail.com November 14, 2025 0
Adjacency Matrix
  • Adjacency Matrix
  • Data Structures

Adjacency Matrix

examhopeinfo@gmail.com November 14, 2025 0

Recent Posts

  • Vivo X200: जाने कितनी कम कीमत पर मिल रहा ये 9400 मिडिया टेक प्रोसेसर वाला स्मार्टफोन
  • Samsung Galaxy S25 Plus पर मिल रही भारी छूट ,जाने सेल प्राइस
  • AI के इस ज़माने में कैसे बिजली बचा रहे हैं यह स्मार्ट प्लग?
  • क्या है यह GhostPairing Scam और बिना पासवर्ड और सिम के क्यों हो रहा है व्हाट्सप्प अकाउंट हैक
  • Leica कैमरे के साथ जल्द लॉन्च हो सकता है Xiaomi Ultra 17

At ExamHope, we understand that preparing for exams can be challenging, overwhelming, and sometimes stressful. That’s why we are dedicated to providing high-quality educational resources, tips, and guidance to help students and aspirants achieve their goals with confidence. Whether you are preparing for competitive exams, school tests, or professional certifications, ExamHope is here to make your learning journey smarter, easier, and more effective.

Quick links

  • About us
  • Contact Us
  • Privacy Policy
  • Terms and Conditions
  • Disclaimer
  • DMCA Policy

Category

  • Computer Network
  • Computer Organization and Architecture
  • Data Structures
  • C Language
  • Theory of Computation
  • Database

You may have missed

Vivo X200 Price Drop
  • IT
  • Current Affairs
  • Tech News

Vivo X200: जाने कितनी कम कीमत पर मिल रहा ये 9400 मिडिया टेक प्रोसेसर वाला स्मार्टफोन

examhopeinfo@gmail.com December 23, 2025 0
Samsung Galaxy S25 Plus
  • IT
  • Current Affairs
  • Tech News

Samsung Galaxy S25 Plus पर मिल रही भारी छूट ,जाने सेल प्राइस

examhopeinfo@gmail.com December 22, 2025 0
Electricity bill saving Smart Plug
  • IT
  • Current Affairs
  • Tech News

AI के इस ज़माने में कैसे बिजली बचा रहे हैं यह स्मार्ट प्लग?

examhopeinfo@gmail.com December 21, 2025 0
Ghost Pairing Scam on Whatsapp
  • IT
  • Current Affairs
  • Tech News

क्या है यह GhostPairing Scam और बिना पासवर्ड और सिम के क्यों हो रहा है व्हाट्सप्प अकाउंट हैक

examhopeinfo@gmail.com December 21, 2025 0
Copyright © All rights reserved for ExamHope. | MoreNews by AF themes.
Go to mobile version