binary search algo Flashcards

1
Q

disadvantage of binary search

A

requires array to be sorted

:. if data is constantly being generated / updated, its difficult to maintain a sorted array (context: social media)

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

when use binary search?

A
  • when array is sorted
  • if t complexity is smaller :. more efficient (still a valid pt even if array size small)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

why use linear instead of binary search?

A
  • when array size is small
  • lower overhead (only counter var required compared to binary which req start mid end var)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

when is linear search faster than binary search?

A
  • let n be the max n(iterations) made by binary search
  • ans: if the element to be searched for is within the first n indexes of the array, linear search will be faster than binary search
How well did you know this?
1
Not at all
2
3
4
5
Perfectly