Sorting and Searching Algorithms Questions

Comparison and non-comparison sorting (quicksort with its pivot and partition choices and hybrid cutoffs, mergesort, heapsort as a sort, insertion/selection/bubble, counting/radix/bucket), their stability, in-place behavior, stack depth and lower bounds, and choosing a sort from input constraints, including near-sorted data, library sorts (Timsort, introsort, language defaults), comparator design and expensive comparisons or copies. Also selection (quickselect, median-of-medians, nth_element), external merge sorting of data larger than memory (run generation and merge passes), and binary search with its variants: first/last occurrence, lower/upper bound, rotated arrays with or without duplicates, peak and mountain arrays, sorted matrices, unbounded search, loop-invariant correctness and off-by-one pitfalls, and binary search on an answer space (discrete or continuous, including k-th smallest by value). Includes divide-and-conquer reasoning for sorts (merge step, merging sorted arrays, median of two sorted arrays, inversion counting). Excludes heap data-structure mechanics and heap-based top-k and k-way merging, trees and tries, general graph search, distributed data-processing systems, approximate nearest-neighbor and streaming-sketch algorithms, and abstract Big-O comparison.

EasyTechnical
47 practiced

Implement selection sort in C++ to sort an array of integers in place. Do not use library sort functions. Provide complexity analysis and explain one scenario where selection sort might be preferable despite O(n^2) time.

EasyTechnical
52 practiced

Explain how the binary search algorithm works on a sorted array. Describe required preconditions, the standard iterative implementation steps, the loop invariants you would maintain, and its time and space complexity. Give two concrete examples of problems where binary search is appropriate and two where it is not, and explain why.

MediumTechnical
58 practiced

Implement an in-place quicksort with a randomized pivot. Keep the recursion depth bounded even on adversarial input, and explain the expected and worst-case running time.

MediumTechnical
60 practiced

How deep can the call stack get in a recursive quicksort and in a recursive merge sort, including on already-sorted or reverse-sorted input? What would you change to keep stack usage bounded in production?

EasyTechnical
56 practiced

List common off-by-one mistakes and mid-calculation errors that cause binary search implementations to loop infinitely or return incorrect indices. For each mistake give a short example input that breaks the incorrect implementation and explain the root cause.

Unlock Full Question Bank

Get access to all 7 Sorting and Searching Algorithms interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.