Merge Sort

First, set the browser to Full Screen view, to give this worksheet and your code as much space as possible.

Then choose either one of the two options below:

Option 1: Start this worksheet from scratch

Option 2: Continue, or view, previous work

This worksheet is copyright © Richard Pawson 2025, and protected by the Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International. You may freely make and distribute copies of this worksheet as is, but if you modify this worksheet you may not distribute your modified version (outside your own teaching institution) without the author's permission. Please email the author to report errors or suggest improvements.

Getting started

From the Demo menu, access the Merge sort code, then select File > Auto Save and complete the dialog to ensure that your code is always saved. Remember that you can use the Undo button (or Ctrl+z) to undo recent changes.

Note that the code contains two functions: sort and merge, plus two tests - one to test each function - with both tests covering multiple test cases (assert instructions). The asserts in test merge are all showing pass because the implementation of the merge function is complete and correct. The asserts in test sort are all failing with the message: actual: [x]. Looking at the code for the sort it is not hard to see why: this is merely a 'skeletal' implementation: sufficient code only to compile, not to run correctly. Your task is to implement sort properly, until all the tests pass. Your implementation should:

1-1: Recursion
1-2: Getting started
1-3: Description of the algorithm
1-4: Some useful coding idioms and hints
1-5: Suggested structure
1-6: First fields shown
1-7: Method calls shown
1-8: The complete solution
Total hints used: /

Notes

Total hints used: /
Worksheet completed.
This worksheet is copyright © Richard Pawson 2025, and protected by the Creative Commons license: Attribution-NonCommercial-NoDerivatives 4.0 International. If you copy and modify this worksheet you may not distribute your modified version (outside your own teaching institution) without the author's permission. Please email the author to report errors or suggest improvements.