Sorting Flashcards

1
Q

What are the three main types of sorting?

A

bubble sort, insertion sort and merge sort.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Describe the advantages and disadvantages of a bubble sort.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain how a bubble sort works.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe the advantages and disadvantages of insertion sort.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

explain how an insertion sort works.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Describe the advantages and disadvantages of a merge sort.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe how a merge sort works.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.

A

5 sorts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly