Sorting & Searching

Master fundamental sorting and searching algorithms and their applications.

Overview

Sorting and searching are fundamental algorithmic techniques. This section covers classic algorithms and their practical applications in interview problems.

Key Concepts

  • Binary search and variants
  • Quick sort and merge sort
  • Counting sort and radix sort
  • Search in rotated arrays
  • Finding kth element
  • Custom comparators

Common Problems

Easy

  • Binary Search
  • Search Insert Position
  • First Bad Version
  • Sqrt(x)

Medium

  • Search in Rotated Sorted Array
  • Find Peak Element
  • Kth Largest Element
  • Merge Intervals

Hard

  • Median of Two Sorted Arrays
  • Count of Smaller Numbers After Self
  • Maximum Gap

Practice Tips

  1. Binary search template: Master the basic template
  2. Sorted input: Look for opportunities to use binary search
  3. Time complexity: Know when O(n log n) is acceptable
  4. Stability: Understand when sort stability matters

Resources