Ternary search meaning in DSA
Last Updated :
03 Apr, 2023
Ternary search is a searching algorithm which is based on divide and conquer principle that works by dividing the search interval into three parts as in binary search the search interval is divided into two parts.
Properties of Ternary Search
- It works only on sorted arrays either ascending or descending.
- The ternary search algorithm divides the particular array into three parts.
- It reduces the number of comparisons, especially if the element is at the end or start of the array.
- In practice, a ternary search may be slower than a binary search for small input sizes but can be faster for larger input sizes.
Types of Data Structures where Ternary Search is used
Like binary search, ternary search can also be used in data structures following the below properties:
- The data structure must be sorted.
- Any element of the data structure can be accessed in constant time.
Applications of Ternary Search
- Searching in databases: Ternary search can be used to efficiently search through large databases.
- Image processing: The algorithm works by finding the threshold value that maximizes the separability between the object and background pixels.
- Optimization in engineering: it can be used to find the maximum or minimum value of a performance function or to optimize a manufacturing process.
- Machine learning: Ternary search can be used in machine learning applications to optimize the hyperparameters of a model. For example, it can be used to find the learning rate that maximizes the accuracy of a classification algorithm.
What else can you read?
Share your thoughts in the comments
Please Login to comment...