Algorithms Flashcards

1
Q

Does the data set need to be ordered for linear search?

A

No.

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

How does linear search work?

A

Get element.
If equal, report found.
If not equal, move to next element.
Repeat until found/end of list.

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

Does data set need to be ordered for binary search?

A

Yes.

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

How does binary search work?

A

Find midpoint –> (start + end)DIV2
If equal to midpoint, report found
If less than midpoint, end = midpoint - 1
If greater than midpoint, beginning = midpoint + 1
Repeat with sublist until found / sublist empty

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

How does insertion sort work?

A

Set the first item as being in the sorted list, while remaining items are in the unsorted list.

While unsorted list has items
- Take first item of unsorted list
While there is an item to the left which is smaller than itself
- swap with that item
Endwhile
Sorted list is now one item bigger
Endwhile
How well did you know this?
1
Not at all
2
3
4
5
Perfectly