2.1 Search and sort Flashcards
Binary search pros/cons
+
Fast for large datasets
Efficient for repeated searches
-
Dataset must be in order
More complex to implement
Linear search pros/ cons
+
Works on unsorted datasets
Faster (than binary) on very small datasets
Simple to understand and implement
-
Slow for large datasets
Inefficient, starts at the beginning each time
Bubble sort
A bubble sort is a simple sorting algorithm that starts at the beginning of a dataset and checks values in ‘pairs’ and swaps them if they are not in the correct order
One full run of comparisons from beginning to end is called a ‘pass’, a bubble sort may require multiple ‘passes’ to sort the dataset
The algorithm is finished when there are no more swaps to make
Insertion sort
The insertion sort sorts one item at a time by placing it in the correct position of an unsorted list. This process repeats until all items are in the correct position
Values in the dataset can move as many places as they need