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

Explain what is...

Câu trả lời

Ternary search is a divide-and-conquer algorithm used to find the position of a specific value in a sorted array. It is similar to binary search, but instead of dividing the array into two parts, it divides it into three parts[1][2][3].

Here's how ternary search works:

  1. The array is divided into three equal parts using two midpoints, mid1 and mid2[2].
  2. The key element is compared with the elements at mid1 and mid2[1][2].
    • If the key is found at mid1 or mid2, their indices are returned[2].
    • If the key is less than the element at mid1, it must lie in the first part, so the search continues in the range [start, mid1-1][2].
    • If the key is greater than the element at mid2, it must lie in the third part, so the search continues in the range [mid2+1, end][2].
    • Otherwise, the key must lie in the middle part, so the search continues in the ra...
senior

senior

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

senior

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

middle

Recursive and Iterative Binary Search: Which one is more efficient and why?

expert

Is Sentinel Linear Search better than normal Linear Search?

Bình luận

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

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