binary search precondition
the list needs to be sorted
Insertion sort
works by dividing a list into two groups: sorted and unsorted. Elements are inserted one by one into their correct position in the sorted section.
linear search
starts at the beginning of a list and checks each item in turn until the desired item is found
Binary search
divides a list in two each time until the item being searched for is found
Four sorting algorithms
Bubble, Insertion, Quick, Merge
Insertion sort words
Make the first item in the list the sorted list. The remaining items are the unsorted list.
While there are items in the unsorted list take the first item of the unsorted list.
While there is an item to the left of it which is smaller than itself swap with that item. End while.
The sorted list is now one item bigger.
End while
Merge sort
splits a list of size n into n lists of size 1. Each pair of lists are merged together in order until there is only one list of size n.
Why does merge split down into unit lists
because a list of length one is sorted
Merge algorithm
Quick sort algorithm
REPEAT:
1. Pick a pivot
2. sort the items either side of the pivot
3. make the items either side of the pivot a sublist
Until length of sublist= 1
Quick sort
The basic idea is to keep splitting a list into two smaller lists, sort those lists using the same quick-sort rules, then split the sub-lists and sort again, until there are only lists of 1 item or less left.
Where can the pivot be applied
The pivot can be applied to any item in the unsorted list.
advantages bubble
disadvantages bubble
advantages insertion
disadvantages insertion
- not as quick as merge/quick sort
disadvantages quick
advantages quick
- no additional storage required/ less stack memory
advantages merge
disadvantages merge
advantages Linear search
disadvantages linear search
advantages binary search
- Quicker
disadvantages binary search
- Cannot deal with unordered lists