topic badge
CanadaON
Grade 8

11.08 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

8.C3.1

Solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves the analysis of data in order to inform and communicate decisions.

8.C3.2

Read and alter existing code involving the analysis of data in order to inform and communicate decisions, and describe how changes to the code affect the outcomes and the efficiency of the code.

What is Mathspace

About Mathspace