Selection Sort Questions for Interview Preparation Set 1

Interview questions on selection sort in data structures. They are in a brief dossier form. Quick answers have been given to each question. Please inform us if you find any mistakes. This is subjective type short answers question and answer set no. 1 in this series.

Last Reviewed and Updated on February 7, 2020
Posted by Parveen(Hoven),
Aptitude Trainer and Software Developer

Interview and Exam Questions and Answers

This set contains a list of commonly asked questions. They are short interview questions aimed at freshers interview, campus placement drives, and also for job interviews. You can use these to have a quick grasp and brush-up of your fundamentals. These questions can be viewed on a mobile phone also because this website is built on responsive web design.

Is selection sort having same efficiency as bubble sort?

Yes, both have same efficiency order of growth.

What is the worst case performance of selection sort?

The worst case performance of selection sort is O(n2).

Selection sort the following array. Show the array after each swap that takes place.
{ 30, 60, 20, 50, 40, 10 }


  1. 30 60 20 50 40 10
  2. 10  60 20 50 40 30 
  3. 10 20  60  50 40 30
  4. 10 20 30  50 40 60 
  5. 10 20 30 40  50  60
  6. 10 20 30 40 50  60 (self-swap)
  7. 10 20 30 40 50 60  (self-swap)

Write an algorithm for selection sort.

  1. Repeat step 2 and 3 varying j from 0 to n-2 //Repeat for n-1 passes
  2. Find the index of the minimum value in arr[j] to arr[n-1]
    1. Set min_index=j
    2. Repeat step c varying i from j+1 to n-1
    3. If arr[i]<arr[min_index]: min_index = i
  3. swap arr[j] with arr[min_index]

Selection sort is suitable for which type of list.

Selection sort is suitable for small list.

What is the best case performance of selection sort?

The best case performance of selection sort is O(n2).

What is the worst case space complexity of selection sort?

The worst case space complexity of selection sort is O(n) total, O(1) auxiliary.

What operation does the Selection Sort use to move numbers from the unsorted section to the sorted section of the list?

The Selection Sort uses the swap operation since it is ordering numbers within a single list.

Write code in java for selection sort algorithm

public void selectionSort(int[] arr)
{

    int i, j, minIndex, tmp;

    int n = arr.length;

    for (i = 0; i < n - 1; i++)
    {

        minIndex = i;

        for (j = i + 1; j < n; j++)
        {

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

                minIndex = j;

            }

            if (minIndex != i)
            {

                tmp = arr[i];

                arr[i] = arr[minIndex];

                arr[minIndex] = tmp;

            }

        }

    }

}


How many comparisons are performed in the second pass of the selection sort algorithm?

n-2 comparisons are performed in the second pass of the selection sort algorithm.

My C/C++ Videos on Youtube

Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.