Sorting Algorithms Flashcards
1
Q
Different types of sort algorithms
A
Bubble Sort
Merge Sort
Insertion Sort
2
Q
Bubble Sort
A
Used to order a list
- Look at first 2 terms
- If ordered move on to next pair
- If not ordered, swap them
- Repeat until you get through all the terms once = pass
- Repeat until there are no swaps in a pass
3
Q
Pros of Bubble Sort
A
Simple Algorithm
Efficient way of checking if a list is in order
Little memory used
4
Q
Cons of Bubble Sort
A
Inefficient to sort a list
Doesn;t work well with large lists
5
Q
Merge Sort
A
- Split list in half (creates 2 sublists)
- Repeat till all sublists contain only 1 term
- Merge 2 sub-lists together and sort into right order
- Repeat Step 3 till all the sub-lists have been merged together
6
Q
Pros of Merge Sort
A
More efficient than bubble sort and insertion sort for large lists
7
Q
Cons of Merge Sort
A
Even if the terms are already sorted, it goes through the whole process
Uses lots of memory
8
Q
Insertion Sort
A
- Look at 2nd term in list
- Compare it to all terms before it and insert number in right place
- Repeat step 2 for all terms
9
Q
Pros of insertion sort
A
Easily coded
Good with small lists
Quick
10
Q
Cons of insertion sort
A
doesn’t cope well with large lists