Search application Flashcards

(10 cards)

1
Q

What should a linear search return if the item is found?

A

• The index of the target

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

What should a linear search return if the item is not found?

A

• -1
• Or another clear ‘not found’ output

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

What important index rule should you remember in search questions?

A

• Lists and arrays are usually 0-indexed

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

In a linear search, when should the algorithm stop?

A

• As soon as the item is found
• Or when the end of the list is reached

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

Which search is better for a small or unsorted list?

A

• Linear search

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

Which search is better for a large sorted list?

A

• Binary search

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

What should you do in a binary search on an even-length list?

A

• Choose middle-left or middle-right
• Then stay consistent

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

What happens in binary search if the target is smaller than the middle value?

A

• Search the left half

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

What happens in binary search if the target is greater than the middle value?

A

• Search the right half

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

When does binary search stop?

A

• When the target is found
• Or when the search range cannot be split further

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