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)
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)
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)
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