Question 11 You have 10 people of different ages.
Sigmoid technical mcq question, verified with a worked answer. Free to practise - no sign-up.
You have 10 people of different ages. The ages are given in the form of an array as (23,13,19,16,22,45,47,51,5). You need to perform sorting of this array using selection sort. What will be the worst case complexity visualised while performing this sort?
Select an option
Show answer & explanation
Answer: B. B) O(n^2)
Selection sort always performs n(n-1)/2 comparisons regardless of the input data, yielding an O(n^2) time complexity in all cases.
Step-by-step Derivation:
Step 1: Selection sort scans the unsorted subarray to find the minimum on each pass.
Step 2: Comparisons = (n-1) + (n-2) + ... + 1 = n(n-1)/2 = O(n^2).