3. Explain or describe the worst-case time complexity, measured in terms of comparisons, of the ternary search algorithm described below. Hint: Follow the way we compute the time complexity of Binary search algorithm procedure ternary \( \operatorname{search}\left(s:\right. \) integer, \( a_{1}, a_{2}, \ldots, a_{n} \) : increasing integers) \( i:=1 \) \( j:=n \) while \( i<j-1 \) \( l:=\lfloor(i+j) / 3\rfloor \) \( u:=\lfloor 2(i+j) / 3\rfloor \) \( \quad \) if \( x>a_{u} \) then \( i:=u+1 \) else if \( x>a_{l} \) then \( i:=l+1 \) \( j:=u \) else \( j:=l \) if \( x=a_{i} \) then location \( :=i \) else if \( x=a_{j} \) then location \( :=j \) else location \( :=0 \) return location \( (0 \) if not found \( ) \)
Added by Ferdinand John D.
Close
Step 1
First, identify the problem you need to solve. What is the input and what is the desired output? Show more…
Show all steps
Your feedback will help us improve your experience
Likhit Ganedi and 58 other Discrete Mathematics educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Recommended Videos
Describe the worst-case time complexity, measured in terms of comparisons, of the ternary search algorithm described in Exercise 27 of Section $3.1 .$
Algorithms
Complexity of Algorithms
Determine the least number of comparisons, or best-case performance, a) required to find the maximum of a sequence of $n$ integers, using Algorithm 1 of Section $3.1 .$ b) used to locate an element in a list of $n$ terms with a linear search. c) used to locate an element in a list of $n$ terms using a binary search.
Determine the worst-case complexity in terms of comparisons of the algorithm from Exercise 5 in Section 3.1 for determining all values that occur more than once in a sorted list of integers.
Recommended Textbooks
Discrete Mathematics and its Applications
Higher Level Mathematics
Discrete Mathematics
Watch the video solution with this free unlock.
EMAIL
PASSWORD