Sorting Algorithms - AP Computer Science A
- Find the primary advantage of using Insertion Sort.
- Efficient for small or nearly sorted arrays. Low overhead and adaptive behavior for special cases.
- What is the space complexity of Quick Sort with in-place partitioning?
- . Recursion depth depends on partition quality.
- What is the key operation in Selection Sort?
- Selecting the minimum element. Finds the smallest unsorted element and places it correctly.
- What is the average-case time complexity of Quick Sort?
- . Good pivot selection typically yields optimal performance.
- What is the typical use of Counting Sort?
- Sorting integers with a known range. Works when the range of values is small and known.
- What is the main advantage of Quick Sort over Merge Sort?
- In-place sorting. Quick Sort uses constant space, while Merge Sort needs space.
- Find the time complexity of Radix Sort.
- . Time depends on number of digits in the largest number.
- State the space complexity of Merge Sort.
- . Requires additional arrays for the merge operation.
- What is the primary benefit of using Heap Sort?
- Consistent time complexity. Guarantees optimal performance regardless of input distribution.
- Identify the sorting algorithm that is not comparison-based.
- Radix Sort. Sorts by digit position rather than comparing elements directly.
- Describe the primary operation of Bubble Sort.
- Repeatedly swapping adjacent elements. Moves larger elements toward the end through adjacent swaps.
- What is the auxiliary space complexity of Heap Sort?
- . Uses the input array itself as the heap structure.
- What is the main disadvantage of using Selection Sort?
- Inefficient time complexity. Always performs same number of operations regardless of input.
- What is the primary disadvantage of using Bubble Sort?
- Inefficiency for large datasets. Quadratic time complexity makes it impractical for large inputs.
- Which sorting algorithm is often used for educational purposes?
- Bubble Sort. Simple logic makes it ideal for teaching sorting concepts.
- What is the primary feature of Timsort?
- Hybrid stable sorting algorithm. Combines merge sort stability with insertion sort efficiency.
- Identify the sorting algorithm used in Python's sorted() function.
- Timsort. Adaptive hybrid algorithm optimized for real-world data.
- What role does partitioning play in Quick Sort?
- Divides array into two parts for sorting. Separates elements smaller and larger than the pivot.
- What is the key operation in Heap Sort?
- Building a max-heap and sorting. Creates heap structure then repeatedly extracts the maximum.
- Find the sorting algorithm with time complexity for a specific case.
- Counting Sort. Works when input values have a small, known range.
- Which algorithm is more efficient for small datasets: Insertion Sort or Merge Sort?
- Insertion Sort. Insertion Sort has lower overhead for small arrays.
- State the stable sorting algorithm suitable for linked lists.
- Merge Sort. Stability and sequential access make it ideal for linked structures.
- What is the space complexity of Counting Sort?
- , where is the range of input. Space grows with the range of input values.
- What is the time complexity of Bubble Sort in the average case?
- . Compares each adjacent pair multiple times through nested loops.
- What is the average-case time complexity of Merge Sort?
- . Divide and conquer approach ensures consistent logarithmic depth.
- What is a characteristic of stable sorting algorithms?
- Preserve relative order of equal keys. Equal elements maintain their original relative positions.
- What time complexity does Selection Sort have in all cases?
- . Always performs the same number of comparisons regardless of input.
- Identify the primary drawback of using Quick Sort.
- Poor worst-case performance. Can degrade to with poor pivot selection.
- Which sorting algorithm is preferred for external sorting?
- Merge Sort. Sequential access pattern suits external storage devices.
- State the best-case time complexity of Insertion Sort.
- . Array is already sorted, requiring minimal shifts.
- Find the best-case time complexity of Bubble Sort.
- . Occurs when array is already sorted, no swaps needed.
- Which sorting algorithm is typically used in Java's Arrays.sort() for objects?
- Timsort. Hybrid algorithm combining merge sort and insertion sort.
- Which sorting algorithm is stable: Quick Sort or Merge Sort?
- Merge Sort. Merge Sort preserves relative order of equal elements.
- What is the worst-case time complexity of Quick Sort?
- . Occurs when pivot is always the smallest or largest element.
- Which sorting algorithm can be easily adapted for singly linked lists?
- Merge Sort. No random access needed, only sequential pointer operations.
- Which sorting algorithm performs well with nearly sorted data?
- Insertion Sort. Adapts well to existing order, requiring fewer operations.