What is the main idea behind the Selection Sort algorithm?
Selection Sort repeatedly finds the smallest element from the unsorted part and moves it to the beginning, sorting the list step by step.
Click to reveal answer
beginner
How many passes does Selection Sort make through the list?
Selection Sort makes n-1 passes through a list of n elements, because after placing n-1 elements, the last one is already sorted.
Click to reveal answer
intermediate
What is the time complexity of Selection Sort in the worst case?
The worst-case time complexity of Selection Sort is O(n²), where n is the number of elements, because it compares each element with all others.
Click to reveal answer
beginner
Does Selection Sort require extra memory for sorting?
No, Selection Sort is an in-place sorting algorithm, meaning it sorts the list without needing extra space beyond a few variables.
Click to reveal answer
beginner
What happens during each pass in Selection Sort?
During each pass, Selection Sort finds the smallest unsorted element and swaps it with the element at the current position, moving the boundary of sorted and unsorted parts.
Click to reveal answer
What does Selection Sort do first in each pass?
ADivides the list into two halves
BSwaps the largest element with the last element
CFinds the smallest element in the unsorted part
DMerges two sorted lists
✗ Incorrect
Selection Sort finds the smallest element in the unsorted part to place it at the beginning.
What is the best-case time complexity of Selection Sort?
AO(n²)
BO(n log n)
CO(n)
DO(log n)
✗ Incorrect
Selection Sort always performs O(n²) comparisons regardless of the input order.
Is Selection Sort a stable sorting algorithm?
ANo, it is not stable
BOnly stable for sorted input
CYes, always stable
DDepends on implementation
✗ Incorrect
Selection Sort is not stable because swapping can change the relative order of equal elements.
How many swaps does Selection Sort perform in the worst case?
AO(n²)
BO(n)
CZero swaps
DO(n log n)
✗ Incorrect
Selection Sort performs at most n-1 swaps, one per pass.
Which of these is true about Selection Sort?
AIt is the fastest sorting algorithm for large data
BIt sorts by repeatedly merging sublists
CIt requires extra memory proportional to input size
DIt selects the minimum element and swaps it
✗ Incorrect
Selection Sort selects the minimum element in each pass and swaps it to the front.
Explain how Selection Sort sorts a list step by step.
Think about how you pick the smallest item and place it at the start repeatedly.
You got /4 concepts.
Describe the time and space complexity of Selection Sort and why.
Consider how many comparisons and swaps happen as the list grows.
You got /3 concepts.
Practice
(1/5)
1. What is the main idea behind the Selection Sort algorithm?
easy
A. Repeatedly find the smallest element and move it to the front
B. Divide the list into halves and sort each half recursively
C. Swap adjacent elements if they are in wrong order repeatedly
D. Use a heap data structure to sort elements efficiently
Solution
Step 1: Understand Selection Sort process
Selection Sort works by finding the smallest element in the unsorted part and swapping it with the first unsorted element.
Step 2: Compare with other sorting methods
Unlike divide and conquer or adjacent swaps, Selection Sort directly selects the minimum each time.
Final Answer:
Repeatedly find the smallest element and move it to the front -> Option A
Quick Check:
Selection Sort = Find min and swap [OK]
Hint: Selection Sort picks smallest element each pass [OK]
Common Mistakes:
Confusing Selection Sort with Bubble Sort
Thinking it divides the list recursively
Assuming it uses extra data structures
2. Which of the following is the correct syntax to swap two elements arr[i] and arr[minIndex] in Java during Selection Sort?
easy
A. arr[i] = arr[minIndex]; arr[minIndex] = arr[i];
B. swap(arr[i], arr[minIndex]);
C. temp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = temp;
D. arr[i], arr[minIndex] = arr[minIndex], arr[i];
Solution
Step 1: Understand Java swap syntax
Java does not have a built-in swap function; we use a temporary variable to swap values.
Step 2: Check each option
temp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = temp; correctly uses a temporary variable. arr[i] = arr[minIndex]; arr[minIndex] = arr[i]; overwrites arr[i] before saving it. swap(arr[i], arr[minIndex]); is invalid syntax. arr[i], arr[minIndex] = arr[minIndex], arr[i]; is Python style, not Java.