Searching and Sorting Algorithms Flashcards

1
Q

When should you use a binary search?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When should you use the different simple sorting algorithms?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do in-place sorting algorithms work?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly