0PricingLogin
Go Academy · Lesson

Searching Sorted Data

Binary search.

Why Search Sorted Data

Once a slice is sorted, you can find elements far faster using binary search instead of scanning every item.

Go's sort package provides search helpers that run in logarithmic time.

Linear vs Binary

A linear search checks each element one by one (O(n)). Binary search halves the search range each step (O(log n)), but requires the data to be sorted first.

All lessons in this course

  1. Sorting Slices
  2. Custom Sort Orders
  3. Searching Sorted Data
  4. Stable Sorting
← Back to Go Academy