![]() |
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.
Let’s explore the detailed time and space complexity of the Ternary Search: Time Complexity of Ternary Search:Best Case Time Complexity: O(1)
Average Case Time Complexity: O(log3 n)
Worst Case Time Complexity: O(log3 n)
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 |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |