|
| 1 | +# Sort |
| 2 | + |
| 3 | +Analyze three sorting programs to determine which algorithms they use. |
| 4 | + |
| 5 | +## Background |
| 6 | + |
| 7 | +Recall from class a few algorithms in which we can sort a list of numbers: selection sort, bubble sort, and merge sort. |
| 8 | + |
| 9 | +* Selection sort iterates through the unsorted portions of a list, selecting the smallest element each time and moving it to its correct location. |
| 10 | +* Bubble sort compares two adjacent values at a time and swaps them if they are in the incorrect order. This continues until the list is sorted. |
| 11 | +* Merge sort divides the list into two repeatedly and then combines the smaller lists back into a larger one in the correct order. |
| 12 | + |
| 13 | +## Instructions |
| 14 | + |
| 15 | +Provided to you are three sorts, `sort1`, `sort2`, and `sort3`. The three sorts implemented are selection sort, bubble sort, and merge sort. Determine the sorting algorithms each sort implements. |
| 16 | + |
| 17 | +* `sort1`, `sort2`, and `sort3` are binary files and cannot be opened by the user. To assess which sort implements which algorithm, run the sorts on different lists of values. |
| 18 | +* Multiple `.txt` files are provided to you. These files contain `n` lines of values, either reversed, shuffled, or sorted. |
| 19 | + * For example, `reversed10000.txt` contains 10000 lines of numbers that are reversed from `10000`, while `shuffled100000.txt` contains 100000 lines of numbers that are in random order. |
| 20 | +* To run the sorts on the text files, in the terminal, run `./[sort_file] [text_file.txt]`. |
| 21 | + * For example, to sort `reversed10000.txt` with `sort1`, run `./sort1 reversed10000.txt`. |
| 22 | +* Record your predictions in `answers.txt`. |
| 23 | + |
| 24 | +### Hints |
| 25 | + |
| 26 | +* You may find it helpful to time your sorts. To do so, run `time ./[sort_file] [text_file.txt]`. |
| 27 | +* The different types of `.txt` files may help you determine which sort is which. Consider how each algorithm performs with an already sorted list. How about a reversed list? Or shuffled list? It may help to work through a smaller list of each type and walk through each sorting process. |
| 28 | + |
| 29 | +{% next %} |
| 30 | + |
| 31 | +## How to Submit |
| 32 | + |
| 33 | +TODO |
0 commit comments