Explain what is...
Explain what is...
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:
mid1
and mid2
[2].mid1
and mid2
[1][2].
mid1
or mid2
, their indices are returned[2].mid1
, it must lie in the first part, so the search continues in the range [start, mid1-1]
[2].mid2
, it must lie in the third part, so the search continues in the range [mid2+1, end]
[2].senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào