Sorting algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637
Question 14
Medium

Complete the trace table for the algorithm shown in Figure 1.

Figure 1

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

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

swappedindextemparr[0]arr[1]arr[2]
true736
false0
737
true
1
767
2
[6]

Sorting algorithms Questions

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