Sorting Flashcards
What are the three main types of sorting?
bubble sort, insertion sort and merge sort.
Describe the advantages and disadvantages of a bubble sort.
It is a simple algorithm and is easy to write the code for. Another advantage is that you don’t need much extra memory as the sorting is done to the original list.
The disadvantages are it is a slow way to sort a list of items. Also, it does not work well with large lists.
Explain how a bubble sort works.
it works its way through the list comparing each pair of items. If the pair is in the wrong order they are exchanged. It repeats these steps until the list is fully ordered.
Describe the advantages and disadvantages of insertion sort.
The advantages are that it is useful for small lists and takes a short time to sort. Also, it is much simpler to code than a merge sort.
The main disadvantage is that much like a bubble sort, it is inefficient with large lists.
explain how an insertion sort works.
An insertion sort works by taking an item and comparing it to the next item in the list. If it is larger than the next item, it will be inserted into its new position If it is smaller, then it will be inserted back into its original place. It repeats these steps until every item in the list is in the right place.
Describe the advantages and disadvantages of a merge sort.
The advantages of a merge sort is that it is the fastest of the three types of sort. Another is that it is also the most efficient for long lists of more than 1,000 items long.
Thje disadvantages of a merge sort is that it is the moist complicated type of sort to code, because of it’s complexity. Also, if there is a large list, a merge sort will use up a large amount of memory, especially if the list is 1,000,000 items long.
Describe how a merge sort works.
A merge sort works by splitting the whole list into increasingly smaller lists and merging the ordered lists back into one. A merge sort divides the list into equally sized lists, and continues until a list contains only one item. Then, it merges the single item lists back togrether, sorting the lists into the right order each time. It repeats this until the list is merged back into one with all the items ordered.
How many sorts would it take for this list to be in alphabetical order if you use a bubble sort? (with A first)
Green, Blue, orange, yellow, purple red, pink.
5 sorts