100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Searching Algorithms Cheat Sheet

Searching Algorithms Cheat Sheet

Covers linear and binary search, graph traversal with BFS and DFS, and guidance on choosing the right search strategy.

1 PageIntermediateApr 15, 2026

Search Strategies

Common approaches to finding data, ordered by typical use case.

  • Linear Search- O(n) time, O(1) space; checks each element sequentially, works on unsorted data
  • Binary Search- O(log n) time, O(1) space; requires sorted data, repeatedly halves the search range
  • Breadth-First Search (BFS)- O(V + E) time; explores a graph level by level using a queue, finds shortest paths in unweighted graphs
  • Depth-First Search (DFS)- O(V + E) time; explores as far as possible along each branch using a stack or recursion
  • Hash-based Lookup- Average O(1) time via a hash table or set; no ordering requirement but uses extra memory

Choosing a Strategy

Matching the search algorithm to the problem.

  • Unsorted, small data- Linear search; the overhead of sorting first isn't worth it for one-off lookups
  • Sorted data, many queries- Binary search or a sorted structure amortizes the O(n log n) sort cost across queries
  • Shortest path, unweighted graph- BFS guarantees the fewest edges to reach a target
  • Exploring all paths- DFS is simpler to implement recursively and uses less memory than BFS for deep graphs
  • Frequent exact-match lookups- A hash set or map beats both linear and binary search with O(1) average time
Pro Tip

Binary search bugs almost always come from the loop bounds or midpoint update — use lo <= hi with lo = mid + 1 / hi = mid - 1, and prefer mid = lo + (hi - lo) // 2 to avoid overflow in fixed-width integer languages.

Was this cheat sheet helpful?

Explore Topics

#SearchingAlgorithms#SearchingAlgorithmsCheatSheet#Programming#Intermediate#SearchStrategies#LinearVsBinarySearch#BFS#DFS#DataStructures#Algorithms#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet