Skip to content
Question

Q.Consider the following randomly ordered numbers stored in a list: 106, 104, 106, 102, 105, 10 Show the content of list after the First, Second and Third pass of the selection sort method used for arranging in ascending order. Note : Show the status of all the elements after each pass very clearly encircling the changes.

(OR)
Consider the following randomly ordered numbers stored in a list: 106, 104, 106, 102, 105, 107 Show the content of list after the First, Second and Third pass of the bubble sort method used for arranging in descending order. Note : Show the status of all the elements after each pass very clearly encircling the changes.
CBSECBSE Class XII Board 2019Subjective· 3mImportance★★★★★
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a) selection sort ascending: passes give [10,104,106,102,105,106], [10,102,106,104,105,106], [10,102,104,106,105,106].

Part (b) bubble sort descending: passes give [106,106,104,105,107,102], [106,106,105,107,104,102], [106,106,107,105,104,102].

Part (a)

Selection sort works by repeatedly selecting the smallest element of the unsorted region and placing it at the front of that region. The list is [106, 104, 106, 102, 105, 10].

  • Pass 1 — scan indices 0..5, the minimum is 10 (at the end); swap it with the first element → [10, 104, 106, 102, 105, 106].
  • Pass 2 — scan indices 1..5, the minimum is 102; swap it into index 1 → [10, 102, 106, 104, 105, 106].
  • Pass 3 — scan indices 2..5, the minimum is 104; swap it into index 2 → [10, 102, 104, 106, 105, 106].

You can verify the trace:

data = [106, 104, 106, 102, 105, 10]
n = len(data)
for i in range(3):                 # first three passes
    mn = i
    for j in range(i + 1, n):
        if data[j] < data[mn]:
            mn = j
    data[i], data[mn] = data[mn], data[i]
    print("Pass", i + 1, ":", data)
Pass 1 : [10, 104, 106, 102, 105, 106]
Pass 2 : [10, 102, 106, 104, 105, 106]
Pass 3 : [10, 102, 104, 106, 105, 106] …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.