topic badge
CanadaON
Grade 9

11.05 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

9.C2.1

Use coding to demonstrate an understanding of algebraic concepts including variables, parameters, equations, and inequalities.

9.C2.3

Read code to predict its outcome, and alter code to adjust constraints, parameters, and outcomes to represent a similar or new mathematical situation.

What is Mathspace

About Mathspace