Câu hỏi phỏng vấn Searching
Câu hỏi

Why use Binary Search if...

Câu trả lời

Binary search is more commonly used than ternary search for a few key reasons:

  1. Binary search has a simpler implementation. In each iteration, you only need to compare the target value to the middle element and decide whether to search the left or right half. Ternary search requires two comparisons to determine whether to search the left, middle, or right third[1][2].

  2. Binary search has a better time complexity in the worst case. The number of comparisons in binary search is \log_2 n, while for ternary search it is \log_3 n. Since \log_2 n < \log_3 n for all n > 1, binary search will always have a lower upper bound on the number of comparisons[1][3].

  3. Binary search is more cache-efficient. By halving the search space each iteration, binary search accesses memory in a more contiguous manner compared to ternary search. This leads to better cache utilization on modern process...

expert

expert

Gợi ý câu hỏi phỏng vấn

expert

When Jump Search is a better alternative than a Binary Search?

middle

Compare Binary Search vs Linear Search

middle

What is an example of Interpolation Search being slower than Binary Search?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào