Skip to content

Course home

Searching and sorting algorithms

Searching and sorting algorithms

EasyMedium
12345678910111213141516171819
Question 9

A bubble sort is one type of sorting algorithm.

A software engineer has written a pseudocode algorithm to perform a bubble sort on a 1D array of drone battery temperatures temps.

temps = [42.1, 38.5, 51.2, 35.0, 40.3]
n = temps.length
swapped = true
while (swapped == true)
    swapped = false
    for i = 0 to n - 2
        if (temps[i] > temps[i + 1])
            temp = temps[i]
            temps[i] = temps[i + 1]
            temps[i + 1] = temp
            swapped = true
        endif
    next i
    n = n - 1
endwhile

A bubble sort contains nested loops. In this pseudocode algorithm, the outer loop is a condition-controlled loop and the inner loop is a count-controlled loop.

Explain why the outer loop needs to be a condition-controlled loop.

[2]
Markscheme

Searching and sorting algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Searching and sorting algorithms

36 exam-style questions on OCR GCSE Computer Science Searching and sorting algorithms. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank