Trace Table - Bubble Sort 3
Trace Table - Bubble Sort 3
For
example, INT (7.5) is 7
START
INPUT Number
IS Number Yes
END
= –1?
No
C 0
D INT(Number/2)
IS
INT(Number/D) Yes
= Number/D?
No
C C + 1
D D – 1
No IS D =
1?
Yes
Yes IS C =
0?
No
OUTPUT C
(a) Complete the trace table for the given algorithm using this input data:
7, 6, 5, 4, –1, 12, 34
Number C D OUTPUT
[6]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
(c) (i) Describe the problem that occurs if a whole number smaller than 4 and not equal to –1
is input.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
(ii) Explain how to change the flowchart to prevent this problem occurring.
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]