Algorithms Flashcards
1
Q
Does the data set need to be ordered for linear search?
A
No.
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.
3
Q
Does data set need to be ordered for binary search?
A
Yes.
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
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