The following code is pseudocode for a very simple sorting algorithm called the Bubble Sort.
Note: the 'to' in for loop is not inclusive of the endpoint.
function bubbleSort( array ):
  size = sizeOf( array )
  for i from 0 to size:
    for j from 0 to (size-i-1):
      if array[j+1] < array[j]:
        #swap array[j+1] with array[j]
        temp = array[j+1]
        array[j+1] = array[j]
        array[j] = temp
Your task is to calculate the number comparisons and moves this algorithm performs on the data below. A 'comparison' in this instance is the check done on line 5. A 'move' is the process of swapping two array items (lines 7-9). You have 2 seconds.

You must be logged in order to submit an answer.

Challenge by ynori7.