Representing algorithms

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
Question 39
Medium

An algorithm is designed to sort a list of three elements in descending order.

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

Some values have already been entered. You may not need to use all the rows in the table.

Figure 1

1  A[0] ← 5
2  A[1] ← 14
3  A[2] ← 9
4  FOR p ← 0 TO 1
5      FOR q ← 0 TO 1
6          IF A[q + 1] > A[q] THEN
7              hold ← A[q]
8              A[q] ← A[q + 1]
9              A[q + 1] ← hold
10         ENDIF
11     ENDFOR
12 ENDFOR

Trace Table

A[0]A[1]A[2]pqhold
5149
[6]

Representing algorithms Questions

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