Searching and Sorting Algorithms Flashcards
When should you use a binary search?
if you happen to have a sorted list already
you plan to do a lot of searching but the list doesn’t change much, so keeping it sorted is easy
you have lots of time to sort, but when they happen, the searches need to be fast
When should you use the different simple sorting algorithms?
Insertion sort: default
Selection sort: good when moving data around is expensive (otherwise, it is not ideal as it does the most comparisons)
Bubble sort: very simple to code, but rarely useful
How do in-place sorting algorithms work?
Separate the array into two parts: a sorted part and an unsorted part and gradually increase the size of the sorted part until everything is sorted