Oh My Algorithm
Algorithm Guidecomplexity: O(log₃ n)

삼진 탐색 (Ternary Search)

구간을 3등분하여 두 개의 중간 지점(mid1, mid2)으로 세 구간을 한 번에 판별합니다. 이진 탐색보다 재귀 깊이는 얕지만 반복당 비교 횟수가 많아, 실제로는 유니모달 함수의 극값 탐색에 주로 사용됩니다.

01 Explore How It Works

Interactive Step-by-Step
Ternary Search
5
12
23
34
45
56
67
78
89
98

삼진 탐색 시작. 구간을 3등분해 두 개의 mid(mid1, mid2)로 세 구간을 한 번에 판별합니다. O(log₃ n).

Logic Node1 / 6

02 Understand It Simply

For Everyone
🔑Analogy

구간을 세 토막으로 나눠 한 번에 두 지점을 보는 것.

💡In Plain Words

구간을 3등분해 두 지점으로 범위를 좁힙니다.

정렬 탐색보다는 주로 볼록(유니모달) 함수의 극값 찾기에 써요.

📍Where It's Used
  • 유니모달 함수의 최적값 찾기

03 Python Implementation

A clean, readable reference implementation of the core logic of 삼진 탐색 (Ternary Search).

core_implementation.py
def ternary_search(arr, low, high, target):
    if low > high:
        return -1
    mid1 = low + (high - low) // 3
    mid2 = high - (high - low) // 3
    if arr[mid1] == target:
        return mid1
    if arr[mid2] == target:
        return mid2
    if target < arr[mid1]:
        return ternary_search(arr, low, mid1 - 1, target)
    elif target > arr[mid2]:
        return ternary_search(arr, mid2 + 1, high, target)
    else:
        return ternary_search(arr, mid1 + 1, mid2 - 1, target)

04 Frequently Asked Questions

FAQ
What is 삼진 탐색 (Ternary Search)?+

구간을 3등분하여 두 개의 중간 지점(mid1, mid2)으로 세 구간을 한 번에 판별합니다. 이진 탐색보다 재귀 깊이는 얕지만 반복당 비교 횟수가 많아, 실제로는 유니모달 함수의 극값 탐색에 주로 사용됩니다.

What is the time complexity of 삼진 탐색 (Ternary Search)?+

The time complexity of 삼진 탐색 (Ternary Search) is O(log₃ n). Follow the step-by-step visualization to see exactly why.

Where is 삼진 탐색 (Ternary Search) used?+

유니모달 함수의 최적값 찾기.

What's a simple analogy for 삼진 탐색 (Ternary Search)?+

구간을 세 토막으로 나눠 한 번에 두 지점을 보는 것.

Guide Progress0%