Searching Algorithms Flashcards

(4 cards)

1
Q

What is a linear search?

A

checks each item in a list one by one until it finds the one you’re looking for or reaches the end

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

What is a binary search?

A

A binary search quickly finds an item by repeatedly dividing the list in half and checking the middle value. If the item is smaller, it searches the left half; if bigger, the right half. It keeps going until it finds the item or the list can’t be divided anymore.

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

What is needed before using a binary search?

A

The list must be sorted in order (like from smallest to largest).

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

Why is binary search more efficient than linear search?

A

Binary search skips over large parts of the list by dividing it in half each time, so it needs fewer steps to find an item.

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