Describe the characteristics of merge sort and bubble sort algorithms. (You will need to know how they work in order to find errors in the algorithm or to stop what the algorithm is doing)
Compares the current location with the next location
Swaps if the data is out of order
No swap if the data is in order (items are maintained in situ)
This continues…
Additional passes (iterations) through the data if there was a swap
If no swaps are performed then the data is sorted in order (has to do one pass to check this!)
This website shows you how a bubble sort it stepped through and is a great visual way of seeing a bubble sort in action.
Click on the red writing (Bubble Sort Algorithm) to access the link
Divide the list into smallest units (divide and conquer!)
Compare each item with the adjacent list
Merge the two adjacent lists
When all lists are merged the data is sorted order
This website shows you how a Merge sort it stepped through and is a great visual way of seeing a Merge sort in action.
Click on the red writing (Merge Sort Algorithm) to access the link
Merge Sort Algorithm:
But which one is faster?
A comparison of bubble sort and merge sort:
Describe the characteristics of linear search and binary search algorithms. (You will need to know how they work in order to find errors in the algorithm or to stop what the algorithm is doing)
1. Compares current location with search item
2. If there is a match it has found what it is looking for
3. Moves to next item in list, until a match or end of the list found
Note: - Data does not have to be sorted before a Linear Search can take place. It is slower but simpler compared to a Binary Search.
1. Calculate a midpoint the data set
2. Check if the item found (midpoint = search item)
3. If not
4. If search item < midpoint then repeat 1 and 2 on left half of data set
5. If search item > midpoint then repeat 1 and 2 on right half of data set
6. Repeat until item found or there is no items left to check
Note: - Data must be sorted before a Binary Search can take place.
It is faster but simpler compared to a Linear Search and is generally used for large data sets.