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.

MediumTechnical
55 practiced

Given user records with name, age and signup timestamp, sort by age ascending and then by signup timestamp descending, keeping the sort stable. Show it with a comparator and with successive stable sorts, and say which you prefer.

EasyTechnical
48 practiced

When is linear search a better choice than binary search? Cover array size, data layout, access cost, unsorted or streaming data, and give two concrete cases for each approach.

EasyTechnical
65 practiced

Write a Java method to find the first (leftmost) occurrence of target in a sorted integer array that may contain duplicates. Signature: public static int firstOccurrence(int[] arr, int target). Explain loop invariants and boundary conditions to ensure correctness.

MediumTechnical
56 practiced

Describe the classic First Bad Version problem where versions are numbered and you have an API isBadVersion(version) that returns a boolean with monotonic behavior. Implement a solution that finds the earliest bad version using O(log n) API calls. Discuss off-by-one pitfalls and test cases.

EasyTechnical
53 practiced

Explain what 'stable sort' and 'in-place sort' mean with concrete examples. Given the list of tuples [(name, age)]: [('alice', 30), ('bob', 25), ('carol', 30)], show a stable and an unstable sort by age and explain why stability matters in multi-key sorting.

Unlock Full Question Bank

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

Sign in to Continue

Join thousands of developers preparing for their dream job.