PGoCareerGoCareer prep tools
Home
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

DSA · Theory

What are linear search and binary search

← All stacks

Theory

208/810

What are linear search and binary search

Don’t start What are linear search and binary search with jargon. Start with folder on disk. That is the whole point.

Do What are linear search and binary search once by hand. left < root < right. Change one input. Say the new result out loud.

Without What are linear search and binary search, a file explorer gets messy and folder on disk is hard to trust.

Rohit ships What are linear search and binary search in a file explorer. That is the use case worth saying.

If folder on disk breaks under What are linear search and binary search, check unbalanced BST becoming a list first.

After What are linear search and binary search, Rohit should still remember unbalanced BST becoming a list.

One breath for What are linear search and binary search, then folder on disk, then unbalanced BST becoming a list. Sit down.

Diagram
  [2, 5, 8, 12, 20]  find 12
         mid=8 → right
              mid=12 found
Exam tip

For What are linear search and binary search: definition + a file explorer + one failure.

Example

def binary_search(arr, target):
    lo, hi = 0, len(arr) - 1
    while lo <= hi:
        mid = (lo + hi) // 2
        if arr[mid] == target:
            return mid
        if arr[mid] < target:
            lo = mid + 1
        else:
            hi = mid - 1
    return -1

print(binary_search([1, 3, 5, 7, 9], 7))

What are linear search and binary search — binary search halves a sorted array each step — O(log n).

Short notes

  • DefWhat are linear search and binary search — Rohit uses it for folder on disk in a file explorer.
  • RuleWhat are linear search and binary search → left < root < right.
  • RememberWhat are linear search and binary search + time vs memory (a file explorer).
  • UseWhat are linear search and binary search in a file explorer (folder on disk).
  • TrapWhat are linear search and binary search — unbalanced BST becoming a list.
  • ExWhat are linear search and binary search → folder on disk.

Questions

1

In one breath: what does What are linear search and binary search do for Rohit?

2

If you skip What are linear search and binary search, what breaks in a file explorer?

3

How do you catch unbalanced BST becoming a list?

4

Change one input on folder on disk. Predict the new result.

Previous← What is iterationNextHash Table vs STL Map →
P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.