Horje
Time and Space Complexity of Ternary Search

The time complexity of Ternary Search is O(log3 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:

Time Complexity of Ternary Search:

Best Case Time Complexity: O(1)

  • When the target element is found at the midpoint of the search interval.

Average Case Time Complexity: O(log3 n)

  • When the target element is not found at the midpoint, but is found within the search interval. This is the average case because, on average, the search interval will be divided into three equal parts, and the target element will be found within one of these parts.

Worst Case Time Complexity: O(log3 n)

  • When the target element is not found within the search interval. In this case, the search interval will be repeatedly divided into three equal parts until it becomes empty. The worst case occurs when the target element is not in the array, and the search interval is divided into three equal parts at each step.

Auxiliary Space of Ternary Search:

The auxiliary space of ternary search is O(log3 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(log3 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(log3 N).




Reffered: https://www.geeksforgeeks.org


Algorithms

Related
When should I use two pointer approach? When should I use two pointer approach?
Is Dijkstra a greedy algorithm? Is Dijkstra a greedy algorithm?
Is exponential search faster than binary search? Is exponential search faster than binary search?
What is a real life example of sorting? What is a real life example of sorting?
How many passes are required in Shell Sort? How many passes are required in Shell Sort?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13