menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Searching ...
source image

Prodevelopertutorial

3w

read

320

img
dot

Searching Algorithm 6: Ternary Search

  • Ternary Search is a divide and conquer algorithm that divides an array into three parts.
  • The steps to perform ternary search are calculating two mid elements, checking if the key element is equal to either mid element, and determining the part of the array in which the key element lies.
  • An example of ternary search is shown with an array [2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 25] and searching for the element 16.
  • The implementation of ternary search in C++ is provided, along with its time complexity of O(log3 n).

Read Full Article

like

19 Likes

For uninterrupted reading, download the app