Searching and sorting algorithms Flashcards

1
Q

Linear search

A

The most simple search algorithm

Each data item is searches in order from the first value to the last. Also works when data is not in order

For large lists, this search is not very efficient

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

Binary search

A

Generally searches through fewer data and is often much quicker, especially for larger data sets

The middle point of the data is selected with each iteration and compared to the value being searches for. Search stops when midpoint matches target value

Data must already be sorted

The upper half or lower half of the data is ignored if the midpoint does not equal the target

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

Merge sort

A

Divides a list into half and again and again until each data item is separate. Then, the items are combined in the same way as they were divided, but now in the correct order. The algorithm then ends

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

Bubble sort

A

Data elements are swapped if they are not in the correct order

The algorithm will only stop when a complete iteration is completed with no swaps made

Not suitable for large sets of data

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

Insertion sort

A

Less complex and efficient than merge sort, but more efficient than bubble sort

Compares values in turn, starting with the second value in the list. If this value is greater than the value to the left of it, no changes are made. Otherwise this value is repeatedly moved left until it meets a value that is less than it. Then starts again with the next value and so on

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