Photo AI

An insertion sort is used to put the following words into ascending alphabetical order - OCR - GCSE Computer Science - Question 2 - 2021 - Paper 1

Question icon

Question 2

An-insertion-sort-is-used-to-put-the-following-words-into-ascending-alphabetical-order-OCR-GCSE Computer Science-Question 2-2021-Paper 1.png

An insertion sort is used to put the following words into ascending alphabetical order. pumpkin flour wall house wall (a) Tick (✓) one box in each row to identify ... show full transcript

Worked Solution & Example Answer:An insertion sort is used to put the following words into ascending alphabetical order - OCR - GCSE Computer Science - Question 2 - 2021 - Paper 1

Step 1

Tick (✓) one box in each row to identify whether each statement about the insertion sort is true or false.

96%

114 rated

Answer

  1. The list of words is initially split into a sorted set and an unsorted set. False
  2. The insertion sort uses a divide stage and then a conquer stage. False
  3. The list of words must be in order before the insertion sort can start. False
  4. Each word is inserted into the correct place in the array, one by one. True
  5. The insertion sort will not work because the word "wall" appears twice. False

Step 2

Explain how a binary search would be used to try to find whether the word "house" appears in this list.

99%

104 rated

Answer

To perform a binary search for the word "house" in the sorted list, follow these steps:

  1. Initial Setup: Start with two indices: low set to 0 (the first index) and high set to 4 (the last index).

  2. Middle Element: Calculate the middle index using the formula:

    mid=low+high2mid = \lfloor \frac{low + high}{2} \rfloor

    which results in mid = 2.

  3. Comparison: Compare the middle element with "house". The middle element is "pumpkin". Since "pumpkin" is greater than "house", update high to mid - 1, making high = 1.

  4. Repeat: Calculate the new mid: now mid = 0. The element at index 0 is "flour", which is also less than "house". Update low to mid + 1, making low = 1.

  5. Final Comparison: Now, low equals high, which means low = 1. The element at index 1 is "house". Since it matches, the search confirms that "house" is present in the list.

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

;