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

  • India Squad for Afghanistan Series Likely to Witness Major Changes, Leadership Reshuffle Possible
  • Brazil Unveils 26-Man Squad for 2026 FIFA World Cup Under Carlo Ancelotti
  • Ruturaj Gaikwad Highlights Squad Challenges After CSK’s Defeat Hurts IPL 2026 Playoff Hopes
  • MS Dhoni Misses CSK Clash Against SRH Due to Fitness Concerns, Ruturaj Gaikwad Shares Update
  • IPL 2026 Playoff Race Heats Up: Rajasthan Royals’ Defeat to Delhi Capitals Changes Top-4 Battle

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

India Squad for Afghanistan Series
  • IT

India Squad for Afghanistan Series Likely to Witness Major Changes, Leadership Reshuffle Possible

examhopeinfo@gmail.com May 19, 2026 0
Brazil Football Team
  • IT
  • Current Affairs
  • Sports News

Brazil Unveils 26-Man Squad for 2026 FIFA World Cup Under Carlo Ancelotti

examhopeinfo@gmail.com May 19, 2026 0
CSK Vs SRH Ipl match
  • IT
  • Current Affairs
  • Sports News

Ruturaj Gaikwad Highlights Squad Challenges After CSK’s Defeat Hurts IPL 2026 Playoff Hopes

examhopeinfo@gmail.com May 19, 2026 0
MS Dhoni News
  • IT
  • Current Affairs
  • Sports News

MS Dhoni Misses CSK Clash Against SRH Due to Fitness Concerns, Ruturaj Gaikwad Shares Update

examhopeinfo@gmail.com May 18, 2026 0
Copyright © All rights reserved for ExamHope. | MoreNews by AF themes.
Go to mobile version