InterviewStack.io LogoInterviewStack.io

Sorting and Searching Algorithms Questions

Core computer science algorithms for ordering and locating data, including understanding, implementing, and applying common sorting algorithms and search techniques and analyzing their performance. Candidates should know comparison sorts such as merge sort, quick sort, heap sort, insertion sort, selection sort, and bubble sort and understand stability, in place versus out of place behavior, and best average and worst case time and space complexities. They should master binary search and linear search and variations and know when searching requires a different approach. Knowledge should include algorithmic patterns such as divide and conquer and two pointers, selection algorithms such as quickselect and nth element, and non comparison sorts such as counting sort, radix sort and bucket sort when appropriate. Candidates must be able to implement clean iterative or recursive versions, reason about recursion depth and stack usage, explain trade offs between using built in language sort utilities and custom implementations, and choose the right algorithm for a problem based on input size, memory constraints, and stability requirements. Interviewers often assess coding correctness, complexity analysis using big O notation, edge cases, comparator usage for custom ordering, and ability to justify algorithm choices.

MediumSystem Design
60 practiced
Design and implement (pseudocode acceptable) a k-way merge algorithm to merge k sorted files into a single sorted output when each file may be large (up to 10GB) but you have limited RAM (8GB). Explain buffering strategy, I/O patterns, min-heap usage and overall complexity statements. Describe how you'd implement this on a single machine and how you'd scale it across multiple machines.
EasyTechnical
65 practiced
Explain non-comparison sorts: counting sort, radix sort, and bucket sort. For each, describe constraints on keys (range, integer vs. float), stability, time and space complexity, and practical applications in AI/data processing (e.g., histogramming integer features, batching by bucketed keys). When would these outperform comparison sorts for large datasets of integers?
HardTechnical
64 practiced
Design a GPU-accelerated sorting pipeline (conceptual) to sort 100M 32-bit keys using CUDA/Thrust or similar primitives. Discuss algorithm choices (radix sort vs sample sort vs merge sort), memory layout for coalesced access, shared-memory optimization, number of kernel launches, and how to integrate the result into a PyTorch data pipeline with minimal PCIe transfers.
HardTechnical
52 practiced
Implement the deterministic linear-time selection algorithm (median of medians) in Python to find the k-th smallest element. Provide correct code that partitions into groups of 5, finds median-of-medians pivot, and achieves worst-case O(n). Discuss constant factors and when you might prefer randomized Quickselect instead.
MediumTechnical
60 practiced
Implement an algorithm in Python to find the median of two sorted arrays (possibly of different lengths) in O(log(min(n, m))) time. Provide code, handle odd/even total length cases, and explain edge cases such as empty arrays and duplicates.

Unlock Full Question Bank

Get access to hundreds of Sorting and Searching Algorithms interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.