topic badge

11.11 Debugging

Interactive practice questions

The list of numbers 4, 9, 8, 1, 6 is to be sorted using the selection sort algorithm.

a

Enter the output after each line of the selection sort algorithm.

Step Number Algorithm Step OUTPUT
$1$1 Find the smallest number.
Swap it with the first number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,
$2$2 Find the second-smallest number.
Swap it with the second number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,
$3$3 Find the third-smallest number.
Swap it with the third number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,
$4$4 Find the fourth-smallest number.
Swap it with the fourth number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,

 

b

A bug is an error in the algorithm which results in the algorithm not producing the desired output.

The algorithm below contains a bug. What is the output of each line of the algorithm?

Step Number Algorithm Step OUTPUT
$1$1 Find the smallest number.
Swap it with the first number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,
$2$2 Find the second-smallest number.
Swap it with the first number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,
$3$3 Find the third-smallest number.
Swap it with the third number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,
$4$4 Find the fourth-smallest number.
Swap it with the fourth number.
$\editable{},\editable{},\editable{},\editable{},\editable{}$,,,,

 

c

Which step contains the bug?

Step 1

A

Step 3

B

Step 4

C

Step 2

D
Easy
4min

The list of numbers 5, 9, 7, 1, 6 is to be sorted using the selection sort algorithm.

Easy
3min

The list of numbers 4, 9, 8, 1, 7 is to be sorted using the insertion sort algorithm.

Easy
4min

The list of numbers 3, 8, 5, 2, 4 is to be sorted using the insertion sort algorithm.

Easy
2min
Sign up to access Practice Questions
Get full access to our content with a Mathspace account

Outcomes

VCMNA282

Use algorithms and related testing procedures to identify and correct errors

What is Mathspace

About Mathspace