Skip to content

Searching algorithms

Searching Algorithms

Searching is the process of finding a specific item in a collection of data.

  • Logic: Check every item one by one from the beginning until you find the match.
  • Best for: Small, unsorted collections.
  • Analogy: Looking for a specific shirt in a messy laundry pile.
  • Logic: Divide and Conquer. Start in the middle. If the target is smaller, look in the left half; if larger, look in the right half. Repeat.
  • Prerequisite: The collection MUST be sorted.
  • Analogy: Looking for a name in a physical phone book.

Efficiency

Binary Search is significantly faster than Linear Search for large datasets, but the data must be sorted first.