Skip to content

Commit b259b8b

Browse files
authored
Update readme.md
1 parent 3709dd7 commit b259b8b

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

‎readme.md‎

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Sorting Algorithms
2-
For the purpose of this module, we will be writing and discussing all sorting algorithms with the assumption that our goal is to sort items in ascending order. But be aware, this does not always have to be the case.
2+
*For the purpose of this module, we will be writing and discussing all sorting algorithms with the assumption that our goal is to sort items in ascending order. But be aware, this does not always have to be the case.*
33

44
## Day 1 - Why is it so important to sort data?
55

@@ -31,7 +31,7 @@ A visualization comparing these two algorithms is shown below.
3131
![binary v sequential](https://www.mathwarehouse.com/programming/images/binary-vs-linear-search/binary-and-linear-search-animations.gif "Binary v Sequential Search")
3232

3333
#### Your Task
34-
- (STRETCH) Complete some of all of the three functions in `searching.py`
34+
- (STRETCH) Complete some or all of the three functions in `searching.py`
3535

3636
#### Runtimes
3737

@@ -50,12 +50,13 @@ While the justification for *WHY* we want to sort our data is pretty clear, a ha
5050
## Iterative Sorting Algorithms
5151

5252
### Selection Sort
53-
***Selection Sort*** is an algorithm that many of you have probably used before when sorting things in your everyday lives. Imagine that you have several books you want to arrange on a shelf from shortest to tallest. You start off by looking for the shortest book, and when you find it, put it on the far left side of the shelf. Then, you look for the second shortest book and insert it directly to the right of the first book. You repeat this process, selecting the next shortest book and moving it next to the most recently placed book, until you have moved all books into the right place. This is ***Selection Sort***.
53+
***Selection Sort*** is an algorithm that many of you have probably used before when sorting things in your everyday lives. Imagine that you have several books you want to arrange on a shelf from shortest to tallest. You start off by looking for the shortest book, and when you find it, put it on the far left side of the shelf. Then, you look for the second shortest book and insert it directly to the right of the first book. You repeat this process, selecting the next shortest book and moving it next to the most recently placed book, until you have moved all books into the correct place. This is ***Selection Sort***.
5454

5555
An example of this algorithm being applied to an array with 10 numerical elements can be seen in the video below.
5656

57-
[(VIDEO) Select-sort with Gypsy folk dance ![alt text](https://i.ytimg.com/vi/Ns4TPTC8whw/hqdefault.jpg)](https://www.youtube.com/watch?v=Ns4TPTC8whw)
57+
[(VIDEO) Select-sort with Gypsy folk dance](https://www.youtube.com/watch?v=Ns4TPTC8whw)
5858

59+
[![(VIDEO) Select-sort with Gypsy folk dance](https://i.ytimg.com/vi/Ns4TPTC8whw/hqdefault.jpg)](https://www.youtube.com/watch?v=Ns4TPTC8whw)
5960

6061
#### Algorithm
6162
1. Start with current index = 0
@@ -107,7 +108,9 @@ Recall that the runtime complexity of an algorithm, often expressed using *Big O
107108
### Insertion Sort
108109
Think back to class or team picture day. Everyone stands in a line facing the photographer. Starting at the left-hand side of the line, the photographer checks to make sure each person is taller than the person next to them. If they are shorter, the photographer pulls them out and shifts people over to the right until he or she finds the right spot for this person. They then insert them back into the line. This process repeats until the photographer reaches the last person on the right-hand side, who must be the tallest person in the group. This is ***Insertion Sort***.
109110

110-
[(VIDEO) Insert-sort with Romanian folk dance ![alt text](https://i.ytimg.com/vi/ROalU379l3U/hqdefault.jpg)](https://www.youtube.com/watch?v=ROalU379l3U)
111+
[(VIDEO) Insert-sort with Romanian folk dance](https://www.youtube.com/watch?v=ROalU379l3U)
112+
113+
[![(VIDEO) Insert-sort with Romanian folk dance](https://i.ytimg.com/vi/ROalU379l3U/hqdefault.jpg)](https://www.youtube.com/watch?v=ROalU379l3U)
111114

112115
#### Algorithm
113116
1. Separate the first element from the rest of the array. Think about it as a sorted list of one element.
@@ -139,7 +142,7 @@ print(arr);
139142
#### Real-World Applications
140143
The answer to the question, "Is ***Insertion Sort*** an efficient algorithm?" is not always the same. The runtime of ***Insertion Sort*** is dependent on how close to being "in-order" the data is to begin with. In a scenario where you are performing ***Insertion Sort*** on an already or mostly sorted array, very few elements will need to be shifted over, leading to a runtime of Ω(n). However, in a worse-case scenario, where the maximum number of shifts are being performed, the runtime of this algorithm is O(n²).
141144

142-
### MVP
145+
### TO-DO in iterative_sorting.py
143146
- Complete the missing parts of `selection_sort()`
144147
- Implement `insertion_sort()` in `iterative_sorting.py`
145148

@@ -179,12 +182,16 @@ Recursive cases *must* be written in a way that will eventually allow us to reac
179182
Your boss asks you to organize an old filing cabinet with 20 years worth of financial documents. He would like things ordered chronologically. You feel overwhelemed. There are thousands of papers in this thing.
180183
So you decide to break this insane task up into more manageable pieces. First, you focus on organizing a single drawer. But this still has a lot of pieces of data that need to be sorted. Within the drawer, you pull out a single folder. You lay out all the contents on a table, grabbing two pieces at a time, placing the older document on top of the newer one. Then, you start merging sorted sets of documents together until the folder is done. Once all the folders have been reassembled, you order the folders correctly in the drawer. And then you put sorted drawers back into the filing cabinet. This idea of breaking a large set of data down into small pieces, sorting the pieces, then merging them back together is what ***Merge Sort*** is all about.
181184

182-
[(VIDEO) Merge-sort with Transylvanian-saxon (German) folk dance ![alt text](https://i.ytimg.com/vi/XaqR3G_NVoo/hqdefault.jpg)](https://www.youtube.com/watch?v=XaqR3G_NVoo)
185+
[(VIDEO) Merge-sort with Transylvanian-saxon (German) folk dance](https://www.youtube.com/watch?v=XaqR3G_NVoo)
186+
187+
[![(VIDEO) Merge-sort with Transylvanian-saxon (German) folk dance](https://i.ytimg.com/vi/XaqR3G_NVoo/hqdefault.jpg)](https://www.youtube.com/watch?v=XaqR3G_NVoo)
188+
183189

184190
#### Algorithm
185191
```
186192
1. While your data set contains more than one item, split it in half
187-
2. Once you have gotten down to a single element, you have also *sorted* that element (a single element cannot be "out of order")
193+
2. Once you have gotten down to a single element, you have also *sorted* that element
194+
(a single element cannot be "out of order")
188195
3. Start merging your single lists of one element together into larger, sorted sets
189196
4. Repeat step 3 until the entire data set has been reassembled
190197
```
@@ -232,7 +239,9 @@ Have you ever wondered how some of the languages you use actually implement thei
232239
### Quick Sort
233240
Let's think about the group photo example again. Everyone's lined up and the photographer wants to order individuals from shortest to tallest. They pull out the first person from the line and instruct everyone *shorter* than this person to position themselves on the left-hand side. Everyone *taller* than this person is instructed to move to the right-hand side. The photographer then repeats this process with the group of people on the left and the group of people on the right. This is ***Quick Sort***.
234241

235-
[(VIDEO) Quick-sort with Hungarian folk dance ![alt text](https://i.ytimg.com/vi/ywWBy6J5gz8/hqdefault.jpg)](https://www.youtube.com/watch?v=ywWBy6J5gz8)
242+
[(VIDEO) Quick-sort with Hungarian folk dance](https://www.youtube.com/watch?v=ywWBy6J5gz8)
243+
244+
[![(VIDEO) Quick-sort with Hungarian folk dance](https://i.ytimg.com/vi/ywWBy6J5gz8/hqdefault.jpg)](https://www.youtube.com/watch?v=ywWBy6J5gz8)
236245

237246

238247
#### Algorithm
@@ -253,8 +262,8 @@ def quick_sort(arr):
253262
#### Real-World Applications
254263
While ***Quick Sort*** has "quick" in its name, it is typically not used as frequently as Merge Sort. Although it *is* quick in a best case scenario, worst case for ***Quick Sort*** is *very* bad. Because of this, it is not often chosen for production.
255264

256-
### MVP
257-
- - Implement `quick_sort()` in `recursive_sorting.py`
265+
### TO-DO in recursive_sorting.py
266+
- Implement `quick_sort()` in `recursive_sorting.py`
258267

259268
### Stretch Goals
260269

@@ -264,4 +273,4 @@ While ***Quick Sort*** has "quick" in its name, it is typically not used as freq
264273
#### Timsort is a combination of the Merge Sort and Insertion Sort algorithms.
265274
- What programming languages use **Timsort** to implement their built-in `sort()` functions?
266275
- If an interviewer asked you to describe the **Tim Sort** algorithm in 3-4 sentences, what would you say?
267-
- Can you implement **Tim Sort** in Python?
276+
- Can you implement **Tim Sort** in Python?

0 commit comments

Comments
 (0)