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

senior

What is the optimal block size for a Jump Search? Explain.

expert

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

senior

Explain what is Ternary Search?

Bình luận

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

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