8.12

### Lecture 22: Merge sortðŸ”—

This assignment is due on Tuesday, March 26 at 11:59pm. Submit it using Handin as assignment lecture22.

Exercise 1. How does merge sort decompose this sorting problem into smaller sorting problems?
 5 6 2 1 8 2 3 7
1. Use this app to draw the decomposition. Make a rectangle for every problem.

2. Click the “Copy to clipboard” button in the lower-left corner of the app.

3. Paste the code as a comment, like this:
 ; Merge sort: ;

 ; A MergeTree is one of: ; - (make-split MergeTree MergeTree) ; - (make-single Number) (define-struct split [former latter]) (define-struct single [element]) (define mt0 (make-single 8)) (define mt1 (make-split mt0 (make-single 2))) (define mt2 (make-split mt1 (make-split (make-single 3) (make-single 7))))

Exercise 2. Define mt3 to be the MergeTree that decomposes this sorting problem:
 5 6 2 1 8 2 3 7

Exercise 3. Write the template for a function that processes a MergeTree. Make it look like a function called process-mergetree, and do not put it in a comment.

Exercise 4. Recall insertion sort from Lecture 19: Follow the template. How does insertion sort decompose this sorting problem into smaller sorting problems?
 5 6 2 1 8 2 3 7
1. Use this app to draw the decomposition. Make a rectangle for every problem.

2. Click the “Copy to clipboard” button in the lower-left corner of the app.

3. Paste the code as a comment, like this:
 ; Insert sort: ;

Optional: Read Chapters 25–26 of the textbook.