Sorting algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637
Question 9
Medium

An automated sensor calibration algorithm sorts temperature readings, recorded as temp_listtemp\_listtemp_list, from three volcanic sectors into ascending order.

The algorithm is represented by the following pseudocode:

1  temp_list ← [8, 2, 5]
2  swapped ← true
3  WHILE swapped = true
4      swapped ← false
5      i ← 0
6      WHILE i < 2
7          IF temp_list[i] > temp_list[i + 1] THEN
8              aux ← temp_list[i]
9              temp_list[i] ← temp_list[i + 1]
10             temp_list[i + 1] ← aux
11             swapped ← true
12         ENDIF
13         i ← i + 1
14     ENDWHILE
15 ENDWHILE

Complete the trace table below to show how the variables and list elements change during the execution of this algorithm.

swappediauxtemp_list[0]temp_list[1]temp_list[2]
true825
false0
828
true
1
858
2
[6]

Sorting algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Sorting algorithms