AS Algorithms Flashcards
How does a linear search work?
Checks each item one by one to see if it is the required item
Advantages and disadvantages of a linear search?
- data set doesn’t need to be ordered
- can be efficient for small data sets
- inefficient for large data sets
When should a linear search be used?
Small, unordered data sets
How does a binary search work?
Starts at the middle of the list, then repeatedly divides it in half, leaving the half with the required item in
What are the advantages and disadvantages of a binary search?
- efficient for large data sets
- requires the data set to be sorted first, alphabetically or numerically
When should a binary search be used?
In large, ordered data sets
How does a bubble sort work?
Examines the first two items, swaps them if they are out of order then examines the next two
Advantages and disadvantages of a bubble sort?
- very easy to implement
- most inefficient piece of shit ever
When should a bubble sort be used?
Small data sets where a small, easy to programme algorithm is required
How does an insertion sort work?
Inserts each item into its correct position in the data set one at a time
Advantages and disadvantages of an insertion sort?
- more efficient than a bubble sort on small data sets
- inefficient on large data sets
Where should an insertion sort be used?
Small, ready sorted lists