โ† Amazon questions

Searching and sorting algorithms with time complexity

Filed under Amazon

Free read 1 of 3

Linear search: O(n), works on unsorted data. Binary search: O(log n), needs sorted data and random access. Hash table lookup: O(1) average, O(n) worst case. BST lookup: O(log n) if balanced, O(n) if skewed.

The question

Explain common searching and sorting algorithms and their time complexities.

Approach

  1. Linear search: O(n), works on unsorted data. Binary search: O(log n), needs sorted data and random access. Hash table lookup: O(1) average, O(n) worst case. BST lookup: O(log n) if balanced, O(n) if skewed.

Tips

  • What they are testing: This question tests whether you know complexities and can say when to choose each algorithm, including stability and space.
  • Common mistake: Quoting quicksort as always O(n log n), without mentioning the O(n^2) worst case.

Related Amazon questions

Collected from public candidate posts and coding forums. Updated Nov 2026.