Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 06 · DSA · Clinic: search, trees, graphs and heaps · about 14 min to read

Play it as a journeyTutor comes with a plan

Clinic #11: Binary Search

Pattern: Binary Search (the invariant) · LC 704

Binary Search
Binary Search · Open board

Ye board dikhata hai ek sorted list ko baar-baar beech se kaatte jaana, har compare pe aadhi list hamesha ke liye phenk di jaati hai, jab tak ek hi ghar na bache.

Before you start. Tumhe bas itna pata hona chahiye ki sorted array kya hai: chhote se bade number tak lagi hui ek list. Ye idea Foundations #01: Complexity (Big-O ka poora naksha) mein “har baar aadha karo” wale idea ke roop mein already dikh chuka hai (engineers use O(log n) kehte hain: list double ho, toh bas ek step aur), is lesson mein wahi idea poora, kaam karta code ban jaata hai.

Lesson 46 of 96 in DSA

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 1946: ek lecture mein binary search ka pehla zikr
  • 2006: bees saal se chhupa hua bug, khud kitab likhne wale ke code mein
  • Ek mota dictionary, aur ek shabd dhoondna hai
  • [lo, hi]: jo baat hamesha sach rehti hai
  • Teen niyam jo bug rokte hain
  • Tum ab jaante ho
  • Problem, seedhe shabdon mein
  • Solution Ladder
  • Sol 1 - linear scan · O(n)
  • Sol 2 - binary search · O(log n) · BEST ✅
  • Trace: nums=[1,3,5,7,9,11]
  • Interview mein pehli baar, raasta
  • The Tell
  • Chala ke dekho: sahi wala, do galat wale, aur ghadi
  • Edge cases, aur wo do bug jo sample pass karte hain
  • Kitne steps, ginke
  • Ghadi: 10,000 queries
  • Loop, flow mein

Terms it explains: LC 704, sorted array, negative, overflow, index, mid, SORTED, BEST, Binary search, O(log n), Clarify, Chhota example, Sorted dekho, INSIGHT, 3-niyam template, Code, Edge, monotone, answer pe binary search, chaaron, `bugLt` (`lo < hi`), aakhri, `bugLoMid` (`lo = mid`), Khaali array, Sab equal, 33 compare, jawab ki value, Search Insert Position.

Review DSA