MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Binary Search: Search Space Elimination, Lower Bound & Upper Bound0%
Study Materials
Data Structures & AlgorithmsProgress 0%
1.1Introduction to DSA, Big-O, Big-Omega & Big-Theta Notations1.2Time Complexity Calculation Rules & Common Runtime Patterns1.3Space Complexity, Auxiliary Memory & Stack vs Heap Allocation
6.1Binary Search: Search Space Elimination, Lower Bound & Upper Bound6.2Binary Search on Answer Space: Allocation & Feasibility Checks6.3Elementary Sorting Algorithms: Bubble, Selection & Insertion Sort (O(n²))6.4Merge Sort: Divide-and-Conquer Paradigm & Stability Analysis6.5Quick Sort: Lomuto vs Hoare Partitioning & Pivot Strategies
HomeTutorialsData Structures & AlgorithmsBinary Search: Search Space Elimination, Lower Bound & Upper Bound
Binary Search on Answer Space: Allocation & Feasibility Checks

Binary Search: Search Space Elimination, Lower Bound & Upper Bound

Beginner12 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

Binary Search is the cornerstone divide-and-conquer searching algorithm. By repeatedly halving the search space of a sorted sequence, binary search locates elements in $O(\log n)$ logarithmic time, searching through 4 billion items in just 32 comparisons!


1. Real-World Analogy: The Guessing Game (1 to 100)

Suppose someone asks you to guess a hidden secret number between 1 and 100:

  • If you guess 1, 2, 3, 4, 5... you might need 100 guesses (Linear Search).
  • Instead, you guess 50! The host says: "Too low!"
  • Instantly, numbers 1 through 50 are eliminated. The search space shrinks from 100 to 50 items in a single guess.
  • Next, you guess 75. The host says: "Too high!"
  • Numbers 75 through 100 are eliminated. In just 7 guesses, you can find any number from 1 to 100 ($2^7 = 128$).

2. The Core Binary Search Algorithm

1Given sorted array: [2, 5, 8, 12, 16, 23, 38, 56, 72, 91], Target = 23
2low = 0, high = 9
3mid = low + (high - low) // 2 = 4 (value: 16)
416 < 23 -> Target is in the RIGHT half -> set low = mid + 1 (index 5)
5mid = 5 + (9 - 5) // 2 = 7 (value: 56)
656 > 23 -> Target is in the LEFT half -> set high = mid - 1 (index 6)
7mid = 5 + (6 - 5) // 2 = 5 (value: 23)
823 == 23 -> TARGET FOUND at index 5!

3. Preventing the Integer Overflow Bug

In languages like C++, Java, and Go, writing mid = (low + high) / 2 can cause a catastrophic 32-bit integer overflow if low + high > 2,147,483,647, wrapping around into a negative number.

Always calculate mid using the mathematically equivalent overflow-safe formula: $$\text{mid} = \text{low} + \left\lfloor\frac{\text{high} - \text{low}}{2}\right\rfloor$$


4. Multi-Language Implementations: Classic & Lower Bound

Python 3:

1def binary_search(nums: list[int], target: int) -> int:
2 low, high = 0, len(nums) - 1
3
4 while low <= high:
5 mid = low + (high - low) // 2
6
7 if nums[mid] == target:
8 return mid
9 elif nums[mid] < target:
10 low = mid + 1
11 else:
12 high = mid - 1
13
14 return -1 # Target not present
15 
16# Lower Bound: First index where nums[index] >= target
17def lower_bound(nums: list[int], target: int) -> int:
18 low, high = 0, len(nums)
19 while low < high:
20 mid = low + (high - low) // 2
21 if nums[mid] >= target:
22 high = mid
23 else:
24 low = mid + 1
25 return low

Modern JavaScript / TypeScript:

1export function binarySearch(nums: number[], target: number): number {
2 let low = 0;
3 let high = nums.length - 1;
4 
5 while (low <= high) {
6 const mid = low + Math.floor((high - low) / 2);
7 
8 if (nums[mid] === target) {
9 return mid;
10 } else if (nums[mid] < target) {
11 low = mid + 1;
12 } else {
13 high = mid - 1;
14 }
15 }
16 
17 return -1;
18}

5. Trace Table: Searching for 70 in [10, 20, 30, 40, 50, 60, 70, 80]

Steplowhighmidnums[mid]ComparisonAction
107340$40 < 70$low = mid + 1 = 4
247560$60 < 70$low = mid + 1 = 6
367670$70 == 70$Target Found at Index 6!

Interactive Quiz• Knowledge Check

Multiple Choice Questions

Question 1
What mandatory prerequisite must be satisfied before Binary Search can be applied to an array?
Question 2
Why is mid = low + (high - low) // 2 preferred over mid = (low + high) // 2?
Question 3
What is the maximum number of comparisons Binary Search requires to search an array of $1,000,000$ sorted elements?
Question 4
What does the "Lower Bound" of a target in a sorted array with duplicates represent?
Question 5
What is the time complexity of Binary Search on a singly linked list?

Next Lesson

Binary Search on Answer Space: Allocation & Feasibility Checks

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Backtracking Mastery: State Space Trees, Subsets, Combinations & PermutationsBinary Search on Answer Space: Allocation & Feasibility Checks

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master Data Structures & Algorithms with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext