Basic Concept
How It Works
Code Understanding
100

What is Selection Sort?

A simple sorting algorithm that repeatedly selects the smallest element and swaps it to the correct position.

100

What is the first step of Selection Sort?

Finding the smallest element in the array.

100

What does the outer loop in Selection Sort represent?

It represents the sorted portion of the array.

200

What does Selection Sort primarily do in each step?

It finds the smallest element in the unsorted part of the array and swaps it to its correct position.

200

What does the algorithm do after finding the smallest element?

It swaps the smallest element with the first unsorted element.

200

What does the inner loop in Selection Sort do?

It finds the smallest element in the unsorted portion of the array.

300

What type of sorting algorithm is Selection Sort?

It is a comparison-based, in-place sorting algorithm.

300

How many times does Selection Sort swap elements in a fully sorted array?

Zero times because no swaps are needed.

300

What will the array {7, 3, 5, 2} look like after one pass of Selection Sort?

{2, 3, 5, 7} (The smallest element 2 is swapped to the first position.)

400

In what type of data structures does Selection Sort work best?

It works best with arrays but is inefficient for linked lists.

400

How does Selection Sort handle duplicate values?

It still sorts them correctly, but it is not stable, so equal elements may change order.

400

What will happen if you forget to swap elements in Selection Sort?

The array will remain unsorted.

500

Does Selection Sort require extra memory to sort an array?

No, it is an in-place sorting algorithm.

500

What happens in the final pass of Selection Sort?

The second-to-last element is compared with the last element, and a final swap is performed if needed.

500

Given this Java snippet, what is missing?

for (int i = 0; i < arr.length - 1; i++) { 

    int minIndex = i; 

    for (int j = i + 1; j < arr.length; j++)  

        if (arr[j] < arr[minIndex])  

            minIndex = j; 

    // ??? 

}


The swap operation

int temp = arr[i];  

arr[i] = arr[minIndex];  

arr[minIndex] = temp;


M
e
n
u