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 — Searching
  • Binary Search
  • Data Structures

Binary Search — Searching

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

Binary Search

💡 What Is Binary Search?

Binary Search is a fast searching technique that works on sorted data.
Instead of checking every element one by one (like in linear search), it keeps dividing the list into halves and focuses only on the half that could possibly contain the element.

Because of this “divide and conquer” idea, Binary Search saves a lot of time — especially when dealing with large datasets.


⚙️ How It Works (Step by Step)

Let’s take an example.
Suppose we have a sorted array:

[5, 10, 15, 20, 25, 30, 35, 40]

and we want to find 25.


🪜 Step 1:

Find the middle element.

  • Start index = 0
  • End index = 7
  • Middle index = (0 + 7) / 2 = 3
  • Middle element = 20

Now compare 25 with 20.

  • 25 is greater, so our target must be on the right half.

We can safely ignore the left half [5, 10, 15, 20].


🪜 Step 2:

Now look at the right half [25, 30, 35, 40].

  • Start index = 4
  • End index = 7
  • Middle index = (4 + 7) / 2 = 5
  • Middle element = 30

Compare again:

  • 25 is smaller than 30, so we ignore everything on the right (30, 35, 40).

🪜 Step 3:

We now look at [25].

  • Start = 4
  • End = 4
  • Middle = 4
  • Middle element = 25

Perfect! ✅ We found our target.


🧠 Why “Binary”?

The word binary means “two.”
At every step, Binary Search splits the list into two parts and works with one part — either left or right.
That’s why it’s called Binary Search.


📈 Binary Search Diagram

Array: [5, 10, 15, 20, 25, 30, 35, 40]
Target: 25

Step 1 → [5, 10, 15, 20, 25, 30, 35, 40]
              ↑
            mid = 20 (Target > mid → search right half)

Step 2 → [25, 30, 35, 40]
              ↑
            mid = 30 (Target < mid → search left half)

Step 3 → [25]
              ↑
            mid = 25 (Found!)

🧩 Real-Life Analogy

Think of finding a friend’s name in your phone contacts (sorted alphabetically).
You don’t scroll one by one — you jump to somewhere in the middle, check if you’ve gone too far or not, and then adjust.
That’s exactly what Binary Search does — it jumps smartly instead of searching blindly.


💻 Simple Pseudocode

binarySearch(array, key):
    start = 0
    end = length(array) - 1

    while start <= end:
        mid = (start + end) / 2
        if array[mid] == key:
            return mid
        else if key < array[mid]:
            end = mid - 1
        else:
            start = mid + 1
    return -1

⏱️ Time Complexity

  • Best case: O(1) → if the element is found in the first comparison.
  • Average/Worst case: O(log₂ n) → because we keep cutting the search space in half each time.

That’s much faster than linear search, which takes O(n) time.


✅ Advantages

  • Extremely fast for large sorted data.
  • Fewer comparisons.
  • Easy to implement using loops or recursion.

⚠️ Limitations

  • Works only on sorted data.
  • Not ideal for linked lists (since you can’t access the middle directly).
  • If data keeps changing, frequent re-sorting is needed.

About the Author

examhopeinfo@gmail.com

Administrator

Visit Website View All Posts

Post navigation

Previous: Radix Sort — Sorting
Next: Interpolation Search — Searching

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