#
CMU 15-112: Fundamentals of Programming and Computer Science

Check7 Practice

Due in Autolab by 10:30am Tue 11-Oct

- You
**must work collaboratively**(no solo!) in groups of 3-6 students - There are no lecture-topic videos to watch this week, instead you must actually attend lecture! If you did not attend lecture (according to our attendance records) on Thu 6-Oct, then you need to attend one of the make-up lectures that we will also provide. We will post those lecture days, times, and locations on piazza.

**Week6 time report and brief reflection**

First, fill out this week6 time report and brief reflection. Thanks!**Review Thursday lecture notes**

As a group, review and discuss the notes from Thursday's lecture. In particular, be sure you understand:- What (approximately) 2
^{10}, 2^{20}, and 2^{30}equal. - What approximately log
_{2}1k, log_{2}1m, log_{2}1b equal. - The fact that logn is much, much smaller than n.
- Why we ignore lower-order terms and constants in Big-O.
- Why we ignore the base in logs in Big-O.
- How selectionSort, bubbleSort, and mergeSort work.
- The proof that selectionSort is O(n
^{2}). - The proof that, for selectionSort (or any quadratic algorithm), when you multiply the input size by c, you multiply the runtime by c
^{2}. - The proof that mergeSort is O(nlogn).
- The fact that, for mergeSort (or any nlogn algorithm), when you multiply the input size by c, you multiply the runtime by a value slightly
larger than c but quite a bit smaller than c
^{2}. - The fact that O(nlogn) is theoretically optimal for any comparison-based sort, and consequently that mergeSort is within a constant time as fast as any possible comparison-based sort.
- These class notes on sorting (in detail!) -- just the sorting section. Be sure to really read these notes, including for example watching the videos of the sorting animations.

- What (approximately) 2
**Review xSortLab**

Still as a group, install xSortLab (see link in course notes mentioned above), and run it, and...- Do a visual sort of bubbleSort, and predict each step before confirming it visually.
- Do a visual sort of selectionSort, and predict each step before confirming it visually.
- Do a visual sort of mergeSort, and predict each step before confirming it visually.
- Do a timed sort of selectionSort, and confirm that doubling the input size increases the runtime by about 4x, and that this prediction grows more accurate as the input size increases.
- Do a timed sort of mergeSort, and confirm that doubling the input size increases the runtime by more than 2x, but just barely, and well under 4x, and that this prediction grows more accurate as the input size increases.

**Rewrite (from scratch, ultimately without notes) sorting.py**

Still as a group, rewrite the code from scratch from sorting.py as we covered in class and as written here. You are responsible for all the code in that file, including bubbleSort, selectionSort, mergeSort (and merge), and the timing and testing code. Be sure to study our implementations, and not others online (and be sure not to use recursion!). You need to know this code very well by Tuesday's lecture!**What to Submit**

We recommend you finish by Monday night though the deadline is 10:30am Tuesday (for everyone, regardless of which lecture you are in, with no late submissions and no grace days):- Submit check7.py, a Python file that contains your sorting code as you wrote it (definitely do not just copy-paste the code from the course website! write it yourself, even if it is extremely similar to ours.)
- At the top of check7.py, also include:
- Your name and andrew id.
- The names and andrew id's of everyone you collaborated with on check7.
- Confirmation that you attended lecture or a make-up lecture (list which one, day/time/location/lecturer).
- Confirmation that your group studied the lecture materials and that you wrote the sorting code from scratch.