PadhaikoAll subjects

Past exam question: 2076 Baisakh (Back), Q9

Data Structure and Algorithms · 8 marks

Open in the Padhaiko app

Topic: Sorting Algorithms

Question

Explain selection sort. Sort the numbers 92, 73, 22, 49, 46, 98, 21, 9, 70 and 63 using selection sort.

Solution

Working Principle of Selection Sort: Selection sort partitions the array into a sorted prefix A[0..i-1] and an unsorted suffix A[i..n-1]. In each pass , it scans the unsorted suffix to find the index minIdx of the smallest element and swaps A[i] with A[minIdx].

Pass-by-Pass Trace on [92, 73, 22, 49, 46, 98, 21, 9, 70, 63]:

Answer:

Sorted sequence using selection sort: 9, 21, 22, 46, 49, 63, 70, 73, 92, 98.

All past exam questions for Data Structure and Algorithms