## Sorting

### Sorting?

Yep — sometimes you’ll be given lists of numbers and a method of sorting them and you have to figure out what the end result will be after sorting the list. All methods of sorting will sort a list, but you might have to repeat the method several times for it to work. I hate sorting, and I’ve never really memorized how they work, so this is just going to be a brief section that will act more as a reference section. We’ll be covering the follow sorting methods: bubble sort, straight selection sort, insertion sort, selection sort, merge sort.

### Bubble Sort

After every pass, adjacent cells are swapped if the left cell is greater than the right. So if we have a list of 5 3 4 1, after one pass it will be 3 4 1 5. Here’s the process: 5>3, so we get 3541. 5>4, so we get 3451. 5>1 so we get 3415.

### Straight Selection Sort

After every pass, it takes the biggest value that is out of order and puts it at the bottom. So if we have 5341, after one pass we’ll get 3415.

### Insertion Sort

Moving left to right, it finds the first number out of place and puts it in the correct place. This is very similar to how many people arrange a hand of playing cards. If we have the list 5341, one pass will give us 3415.

### Selection Sort

Finds the smallest number and swaps it with the position it should be in. If we have 5341, it will return 1345 after one pass. Note: It is just a fluke that this method put the list in order after one pass. This will not always happen.

### Merge Sort

This is a strange method that I don’t really fully understand. Essentially it splits up lists in half several times, then orders each split group. I’m not sure how the process works step-by-step, but you should be familiar with the basic idea of how it works.

### Conclusion

Sorting is a very small part of WYSE testing…the most popular sorting I’ve seen was the bubble sort when you’re asked to give the value of a list after one pass. If you’re serious about WYSE tests I would memorize how each method works.

Previous: Conditional Logic
Next: Binary Trees