Skip to content

Course home

Searching and sorting algorithms

Searching and sorting algorithms

EasyMedium
1234567891011121314151617
Question 9

An environmental monitoring system tracks the water acidity of various lake samples. An insertion sort algorithm is implemented in pseudocode to sort a 1D array of these pH measurements, pH_levels, into descending numerical order.

pH_levels = [6.8, 7.4, 5.2, 8.1, 4.5]
for i = 1 to pH_levels.length - 1
    ptr = i
    while (ptr > 0 and pH_levels[ptr] > pH_levels[ptr - 1])
        temp_val = pH_levels[ptr]
        pH_levels[ptr] = pH_levels[ptr - 1]
        pH_levels[ptr - 1] = temp_val
        ptr = ptr - 1
    endwhile
next i

Describe the purpose of the variable temp_val in this algorithm.

[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