Time and Space Complexity of Ternary Search (original) (raw)

Last Updated : 23 Jul, 2025

The t**ime complexity** of Ternary Search is **O(log 3 N), where **N is the size of the array. In terms of space complexity, ternary search requires only **O(1) auxiliary space, as it operates directly on the given array without creating any additional data structures.

Feature Ternary Search
Time Complexity O(log3N)
Auxiliary Space O(log3 N)

Let's explore the detailed time and space complexity of the Ternary Search:

**Best Case Time Complexity: O(1)

**Average Case Time Complexity: O(log 3 n)

**Worst Case Time Complexity: O(log 3 n)

The **auxiliary space of ternary search is **O(log 3 N), where **N is the number of elements in the ternary search tree. This complexity is primarily due to the recursive call stack.

**Recursive Calls Stack: O(log 3 N)

Ternary search uses recursion to traverse the ternary search tree. Each recursive call creates a new stack frame, which requires additional memory space. The maximum depth of the recursion is equal to the height of the ternary search tree, which can be as large as O(log 3 N).