Skip to content

Course home

Searching and sorting algorithms

Searching and sorting algorithms

EasyMedium
1234567891011121314151617
Question 8

An insertion sort is a common sorting algorithm.

A seismologist designs a pseudocode algorithm to sort an array of earthquake magnitudes, magnitudes, into descending order.

magnitudes = [5.2, 6.8, 4.1, 7.3, 5.9]
for p = 1 to magnitudes.length - 1
    current_pos = p
    while (current_pos > 0 and magnitudes[current_pos] > magnitudes[current_pos - 1])
        temp = magnitudes[current_pos]
        magnitudes[current_pos] = magnitudes[current_pos - 1]
        magnitudes[current_pos - 1] = temp
        current_pos = current_pos - 1
    endwhile
next p

Describe the purpose of the variable temp 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