The following exercises provide you with the opportunity to practice with Mergesort and bytecode. The solutions to these exercises are found in the section .
Say that we want to Mergesort the array [1, 5, 2, 7, 4, 3, 6, 8]. Fill in the chart to demonstrate how Mergesort recursively breaks down the array:

Let’s continue with the example from the previous exercise. Fill in the next chart to show how Mergesort merges all the values to produce a completely sorted array:

New Concept: Each data element that follows consists of two pieces: the first (top) piece is the primary data itself—an integer—and the second (bottom) piece is a timestamp of when that integer was created. Currently, the array is sorted in terms of the timestamp, but now we want to use Mergesort to sort the array by the integers themselves:

Use pencil and paper (or whatever) to walk through all the steps of Mergesort. What do you notice about the sorted array once you’re done?
Write a Python loop that prints out the integers 1 through 10. Then, produce the bytecode for your Python code. What do you get?
Now, write a second version of the same program using a different type of loop (such as a while loop instead of a for loop, for example). Produce the bytecode for this version as well and compare the two sets of bytecode. What aspects of the two sets of bytecode seem similar, and what aspects seem different?
There’s no right or wrong answer to this exercise. It’s just to give you practice with generating bytecode and (lightly) analyzing it.