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

Python · Theory

Searching Algorithms in Python

← All stacks

Theory

74/268

Searching Algorithms in Python

Linear search walks left to right — works on any list, O(n). Binary search cuts half each time — list must be sorted, O(log n).

If they say binary search, first sentence is “sorted”. Unsorted binary search is wrong.

Searching Algorithms in Python — output — True then 1. Linear membership. Binary search needs a sorted list.

Exam tip

Linear vs binary: sorted or not + complexity.

Example

# Searching Algorithms in Python
a = [70, 90, 80]
print(90 in a)
print(a.index(90) if 90 in a else -1)

Searching Algorithms in Python — output: True then 1. Linear membership. Binary search needs a sorted list.

Short notes

  • Linear : scan all, any list.
  • Binary : sorted only, mid.
  • TrapBinary on unsorted data.

Questions

1

Explain Searching Algorithms as if you are teaching a junior — definition, then one tiny script.

2

What does the example print, and why?

3

What mistake do freshers make with Searching Algorithms?

Previous← Context Manager in PythonNextLinear Search in Python →
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.