Photo AI

A student has written a pseudocode algorithm to perform an insertion sort on a 1D array names - OCR - GCSE Computer Science - Question 3 - 2023 - Paper 2

Question icon

Question 3

A-student-has-written-a-pseudocode-algorithm-to-perform-an-insertion-sort-on-a-1D-array-names-OCR-GCSE Computer Science-Question 3-2023-Paper 2.png

A student has written a pseudocode algorithm to perform an insertion sort on a 1D array names. names = ["Kareem", "Sarah", "Zac", "Sundip", "Anika"] for count = 1 t... show full transcript

Worked Solution & Example Answer:A student has written a pseudocode algorithm to perform an insertion sort on a 1D array names - OCR - GCSE Computer Science - Question 3 - 2023 - Paper 2

Step 1

Describe the purpose of the variable temp in the insertion sort pseudocode algorithm.

96%

114 rated

Answer

The variable temp is used as a temporary storage location during the insertion sort process. When elements in the array need to be shifted to make space for the insertion of a smaller element, temp holds the value of the element currently at the position pos. This allows the algorithm to correctly swap elements without losing the original value of the one that is being moved.

Step 2

Describe one difference between an insertion sort and a bubble sort.

99%

104 rated

Answer

One key difference between insertion sort and bubble sort is their method of sorting. Insertion sort builds a sorted portion of the array one element at a time, moving elements to their correct position. Conversely, bubble sort repeatedly steps through the list, comparing adjacent elements and swapping them if they are in the wrong order, resulting in larger elements 'bubbling' to the top with each complete pass through the array.

Join the GCSE students using SimpleStudy...

97% of Students

Report Improved Results

98% of Students

Recommend to friends

100,000+

Students Supported

1 Million+

Questions answered

Other GCSE Computer Science topics to explore

;