Searching and sorting algorithms
14
0/2

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]

Searching and sorting algorithms Questions

Practise OCR GCSE Computer Science Searching and sorting algorithms with exam-style questions for GCSE Computer Science. 36 questions, matched to the OCR GCSE Computer Science (J277) specification and written in Component 01 and Component 02 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.

PreviousNext

Searching and sorting algorithms Questions

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