Senior 7 min · March 05, 2026

Ternary Search Fails on Non-Strictly Unimodal Functions

Ternary search dropped model accuracy 15% due to a plateau.

N
Naren · Founder
Plain-English first. Then code. Then the interview question.
About
 ● Production Incident 🔎 Debug Guide
Quick Answer
  • Ternary search finds the extreme value (max or min) of a unimodal function in O(log n) time.
  • It divides the search range into three equal parts using two midpoints m1 and m2.
  • Comparing f(m1) and f(m2) lets you discard one third of the range each iteration.
  • Performance: converges in O(log_1.5 n) iterations — about 1.7 times more iterations than binary search.
  • Production trap: incorrect handling of equality (f(m1)==f(m2)) can skip over the extremum.
  • Biggest mistake: assuming integer arrays work like continuous search — discrete search needs a different stop condition.
Plain-English First

Imagine you're trying to find the sweetest spot on a hill — you don't know exactly where it is, but you know the hill only goes up and then back down. Instead of checking every single point, you pick two spots that divide the hill into three equal sections, taste both, and throw away the third that definitely can't be the sweetest. You keep doing this — splitting what's left into thirds — until you've zeroed in on the peak. That's ternary search: a way to find the best point on a single-humped curve by confidently eliminating a third of the possibilities each step.

Most engineers encounter binary search early and carry it like a trusty Swiss Army knife for the rest of their careers. But there's a whole class of problems — optimizing a physics simulation, tuning a cost function, finding the peak throughput of a network — where binary search simply can't help, because the data isn't sorted in the classical sense. It rises to a peak and then falls, forming a shape mathematicians call unimodal. Ternary search was designed exactly for this shape, and understanding it unlocks a family of optimization problems that would otherwise require calculus or brute-force scanning.

The core problem ternary search solves is this: given a unimodal function f(x) over a continuous or discrete domain, find the value of x that maximizes (or minimizes) f(x), without evaluating the entire domain. Binary search needs a sorted, monotonic sequence to compare against a target. Ternary search instead compares the function's output at two interior probe points — m1 and m2 — to decide which third of the search space cannot contain the optimum. Each iteration shrinks the search space to two-thirds of its previous size, converging on the answer exponentially fast.

By the end of this article you'll be able to implement both the iterative and recursive flavours of ternary search in Java, articulate exactly why it converges in O(log₃ n) iterations, know when to prefer it over binary search or golden-section search, avoid the three most common implementation bugs that cause infinite loops or missed answers, and answer the ternary search questions that show up in FAANG-level interviews. Let's build this from first principles.

What is Ternary Search? — Plain English

Ternary search finds the minimum or maximum of a unimodal function — a function that has exactly one peak (for maximum search) or one valley (for minimum search). Unlike binary search which requires a sorted array, ternary search works on unimodal functions: the function increases then decreases (for max) or decreases then increases (for min). The algorithm divides the current range into three equal parts using two midpoints m1 and m2. Comparing f(m1) and f(m2) eliminates one-third of the range: if f(m1) < f(m2), the maximum cannot be in [lo, m1]; if f(m1) > f(m2), the maximum cannot be in [m2, hi]. This continues until the range is small enough.

The Two-Probe Intuition
  • You have a unimodal 'hill' — up one side, down the other.
  • Pick two points dividing the hill into thirds.
  • If the left point is lower than the right, the peak can't be left of the left point — discard that third.
  • If the left is higher, the peak can't be right of the right point — discard that third.
  • If they're equal, the peak is between them — discard the outer thirds.
Production Insight
In production, no function is strictly unimodal.
Noise, rounding, or measurement errors can create small local fluctuations.
Always add an epsilon tolerance and validate with a known test case before trusting the result.
Key Takeaway
Ternary search works on any unimodal function, no derivative needed.
It's the go-to algorithm when you have a 'one-hump' problem and a black-box evaluator.
Know its limit: strict unimodality — no plateaus, no noise.

How Ternary Search Works — Step by Step

Ternary search for maximum of unimodal function f on range [lo, hi]:

  1. While hi - lo > epsilon (or for integers, while hi - lo > 2):
  2. a. m1 = lo + (hi - lo) / 3.
  3. b. m2 = hi - (hi - lo) / 3 (equivalently, lo + 2*(hi-lo)/3).
  4. c. If f(m1) < f(m2): maximum is not in [lo, m1-1] → set lo = m1 + 1.
  5. d. If f(m1) > f(m2): maximum is not in [m2+1, hi] → set hi = m2 - 1.
  6. e. If f(m1) == f(m2): maximum is in [m1+1, m2-1] → lo = m1+1, hi = m2-1.
  7. Check remaining elements in [lo, hi] for the maximum.

For minimum search, reverse the comparisons: if f(m1) > f(m2), minimum is not in [lo, m1-1].

Integer vs Floating-Point Pitfall
When using integer indices, 'hi - lo > 2' is the correct stop condition, not '>= 2'. If you stop at 'hi - lo >= 2', you might miss the last three elements. For floating-point, never use a fixed number of iterations — always check hi - lo < epsilon or use a maximum iteration count as a safety net.
Production Insight
The most common production bug is an off-by-one in the equality branch.
If f(m1)==f(m2), the extremum lies strictly between m1 and m2, so set lo=m1+1 and hi=m2-1 (not lo=m1 and hi=m2).
Always test with a known unimodal array like [1,3,5,4,2] before deploying.
Key Takeaway
For integers: stop when range <= 2, then check all survivors.
For continuous: stop on epsilon or max iterations — never both.
The equality branch is the trickiest — get it right or the algorithm fails silently.

Worked Example — Finding Maximum in Array [1,3,5,4,2]

Array: [1,3,5,4,2], indices 0-4. Maximum is at index 2 (value 5).

Round 1: lo=0, hi=4. m1=0+(4-0)/3≈1, m2=4-(4-0)/3≈2 (integer: m1=1, m2=3). f(m1)=arr[1]=3, f(m2)=arr[3]=4. f(m1)<f(m2) → maximum not in [0,m1]=[0,1] → lo=m1+1=2.

Round 2: lo=2, hi=4. m1=2+(4-2)/3≈2, m2=4-(4-2)/3≈3 (m1=2, m2=3). f(m1)=arr[2]=5, f(m2)=arr[3]=4. f(m1)>f(m2) → maximum not in [m2+1,hi]=[4,4] → hi=m2-1=2.

Round 3: lo=2, hi=2. hi-lo=0 <= 2 threshold. Check [2,2]: arr[2]=5. Maximum at index 2.

Each round eliminates ~1/3 of remaining range. Total iterations: O(log_1.5(n)) ≈ O(log n).

Why the Worked Example Matters
This small example exposes the two most critical implementation details: integer division rounding and the stop condition. Notice that in Round 2, m1 == 2 and m2 == 3 — they are only 1 apart. This is fine because we still compare and eliminate. If the range were larger, m1 and m2 would be spaced further apart.
Production Insight
Trace through this example by hand before writing any production code.
It reveals that after just two rounds, the range shrinks from 5 elements to 1.
The stop condition 'hi-lo <= 2' means we never skip the maximum — always verify remaining elements.
Key Takeaway
Ternary search eliminates roughly one third per round.
For a 5-element array, two rounds suffice.
Always trace a short example — it catches logic errors that unit tests miss.

Integer Stopping Criterion: Why Stop When hi - lo ≤ 2?

The integer stopping criterion is deceptively simple but often misused. The standard condition is while (hi - lo > 2). This ensures that the remaining range has at least 4 elements, because when hi - lo <= 2, we cannot safely compute two distinct midpoints — m1 and m2 might coincide or even cross each other due to integer division truncation. For example, if hi - lo = 2, then the range has 3 elements. Computed m1 = lo + (hi-lo)/3 = lo, m2 = hi - (hi-lo)/3 = hi. These are distinct (lo and hi) but there is no interior point; the algorithm would not have enough room to eliminate a third. So we stop and linearly scan the remaining 2 or 3 elements. If we used hi - lo >= 2, the loop would continue with a 3-element range, causing potential infinite loops or incorrect updates. In competitive programming, this subtlety is a frequent source of penalties. Always remember: stop when the range size is 3 or less, then brute force the survivor list.

Production Insight
In production integer indexes, using the wrong stop condition is the #1 reported ternary search bug. Always test with arrays of length 3 and 4: a 3-element array should exit the loop immediately and scan all three.
Key Takeaway
For integer arrays, the correct stop condition is hi - lo > 2. Once the range has 3 or fewer elements, linearly scan them. Never use >= 2.

Implementation

Ternary search divides the range into thirds using two probe points. The implementation handles both discrete (integer index) and continuous (floating-point) variants. For continuous optimization, iterate until hi-lo < epsilon (e.g., 1e-9). For integer arrays, iterate until hi-lo <= 2 and check remaining elements directly. Ternary search is less common than binary search because it requires unimodal functions, but it is essential for competitive programming problems involving bitonic arrays or geometric optimization.

ternary_search.pyPYTHON
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def ternary_search_max_array(arr):
    """Find index of maximum in unimodal array."""
    lo, hi = 0, len(arr) - 1
    while hi - lo > 2:
        m1 = lo + (hi - lo) // 3
        m2 = hi - (hi - lo) // 3
        if arr[m1] < arr[m2]:
            lo = m1 + 1
        elif arr[m1] > arr[m2]:
            hi = m2 - 1
        else:
            lo, hi = m1 + 1, m2 - 1
    return max(range(lo, hi + 1), key=lambda i: arr[i])

def ternary_search_min_continuous(f, lo, hi, iterations=200):
    """Find x in [lo,hi] that minimizes f (unimodal, continuous)."""
    for _ in range(iterations):
        m1 = lo + (hi - lo) / 3
        m2 = hi - (hi - lo) / 3
        if f(m1) < f(m2):
            hi = m2
        else:
            lo = m1
    return (lo + hi) / 2

# Discrete: find max of [1,3,5,4,2]
print(ternary_search_max_array([1,3,5,4,2]))  # 2 (index)

# Continuous: minimize (x-3)^2 on [0,10]
f = lambda x: (x - 3) ** 2
print(round(ternary_search_min_continuous(f, 0, 10), 6))  # ~3.0
Output
2
3.0
Production Insight
The most frequent production bug is using the same stop condition for both integer and continuous search.
Integer search stops at range <= 2; continuous search must use a tolerance or max iterations.
Always add a safety max iteration limit (e.g., 200) to continuous variants to prevent infinite loops due to epsilon being too small.
Key Takeaway
Write the integer and continuous versions separately — don't force one function to handle both.
The integer version uses integer division and a tight loop; the continuous version uses floating division and iteration count.
Test both with known edge cases (array of size 3, plateau-like data).
When to Use Each Variant
IfFunction is continuous and differentiable
UseUse binary search on derivative — fewer evaluations.
IfFunction is discrete (integer array) and unimodal
UseUse integer ternary search with while (hi-lo > 2).
IfFunction evaluations are expensive and derivative unavailable
UseUse golden-section search — reuses earlier evaluations for faster convergence.
IfRange is small (size < 10)
UseBrute-force scan — overhead of ternary search isn't worth it.

Complexity Analysis and Real-World Applications

Each iteration reduces the search range to approximately 2/3 of its previous size. For a range of length n, the number of iterations needed is log_{3/2}(n) ≈ (log n) / (log 1.5) ≈ 1.71 * log2 n. So time complexity is O(log n), but with a higher constant than binary search.

Real-world applications
  • Hyperparameter tuning (learning rate, batch size) in machine learning.
  • Finding optimal operating points in control systems (e.g., speed vs fuel efficiency).
  • Competitive programming problems involving 'bitonic' arrays or unimodal cost functions.
  • Physics simulations where you need to find the point of maximum energy or stress.

Ternary search is not a replacement for binary search — they solve different problems. Binary search works on monotonic predicates; ternary search works on unimodal functions.

Log Base 1.5 — The Real Cost
  • Binary search halves the range: log2 n iterations.
  • Ternary search reduces to 2/3: log1.5 n iterations.
  • log1.5 n ≈ 1.71 * log2 n — about 70% more iterations.
  • Each iteration of ternary search evaluates f twice (vs once for binary search on derivative).
  • So total function evaluations for ternary: ~3.4 log2 n; for binary on derivative: ~1 log2 n.
Production Insight
In a real production system, function evaluations often dominate runtime.
If each evaluation takes seconds (e.g., large ML model), the extra iterations of ternary search can be painful.
Consider golden-section search instead — it converges faster for the same number of evaluations.
Always benchmark before committing to ternary search in latency-sensitive systems.
Key Takeaway
Ternary search is O(log n) but with a higher constant than binary search.
It's only justified when the problem is truly unimodal and derivatives are unavailable.
For expensive functions, golden-section search is almost always the better choice.

Time Complexity Derivation with Master's Theorem

To formally derive the time complexity, set up the recurrence relation. Each iteration of ternary search reduces the problem size from n to roughly 2n/3 (since we discard at least one third of the range) and performs O(1) work (calculating two midpoints, two function evaluations, and a comparison). Therefore:

T(n) = T(2n/3) + O(1)

This fits the form T(n) = a T(n/b) + f(n) with a = 1, b = 3/2, and f(n) = Θ(1) = Θ(n^0).

Compute n^(log_b a) = n^(log_{3/2} 1) = n^0 = 1.

Since f(n) = Θ(1) = Θ(n^0), we are in case 2 of the Master Theorem (f(n) = Θ(n^c) with c = log_b a). Therefore, T(n) = Θ(n^c log n) = Θ(1 * log n) = Θ(log n).

The base of the logarithm is 3/2, but in big-O notation the base is irrelevant. The important takeaway: ternary search runs in logarithmic time, with the constant factor determined by the base 3/2.

Production Insight
The Master Theorem derivation is not just theoretical. If your implementation does additional work per iteration (e.g., copying arrays or logging), the f(n) term becomes larger and the complexity may increase. Always measure actual runtime against the theoretical model.
Key Takeaway
Ternary search's O(log n) complexity is rigorously derived from T(n)=T(2n/3)+O(1) via Master Theorem case 2. The base of the logarithm is 3/2.

Golden Section Search: A More Efficient Variant

Golden Section Search is a variant designed for expensive function evaluations. Instead of choosing two new midpoints each iteration, it reuses one evaluation from the previous step by splitting the interval according to the golden ratio φ ≈ 1.618. The interval is divided so that the ratio of the larger part to the whole equals the ratio of the smaller part to the larger part: (a+b)/a = a/b = φ.

Given interval [lo, hi], the two probe points are
  • m1 = hi
  • (hi
  • lo) / φ
  • m2 = lo + (hi
  • lo) / φ

Initially we evaluate f(m1) and f(m2). In subsequent iterations, depending on which region is discarded, one of these points becomes the interior point of the new interval. For example, if f(m1) < f(m2) (min search), the new interval becomes [m1, hi] and m2 becomes the new lo? Actually, the new lo becomes m1, and the old hi stays. The new interior point is the old m1 (now at a position proportional to φ). So only one new evaluation is needed per iteration.

Compared to ternary search, golden section search
  • Needs one new evaluation per iteration (ternary needs two).
  • Converges with factor ≈0.618 vs 0.666 per iteration.
  • Requires roughly 29 iterations for n=1e6 vs 34 for ternary.
  • Is optimal among minimax algorithms for unimodal functions.

For production systems where each function call is costly (e.g., running a physics simulation), golden section search is the clear winner.

Golden Ratio in Practice
Golden section search is often implemented with a fixed precomputed φ = (1 + sqrt(5)) / 2. Avoid recomputing the ratio inside the loop. While ternary search is easier to reason about, golden section search's single-evaluation-per-iteration advantage makes it the preferred choice in many optimization libraries.
Production Insight
If you're optimizing a black-box function that takes minutes to evaluate, switch from ternary search to golden section search immediately. The savings in total evaluations (roughly 15% fewer) can translate to hours of saved compute time.
Key Takeaway
Golden section search reuses one function evaluation per iteration, converging faster than ternary search per evaluation. Use it when evaluations are expensive and derivatives are unavailable.

C++ mirrors the Java implementation but benefits from templates and the standard library. For integer arrays, we use int or long long depending on the index range. The same stop condition hi - lo > 2 and the linear scan of the remaining elements apply. The code below demonstrates both a function template for generic containers and a specialized version for std::vector<int>. Note that for continuous search, the same technique applies using double and a fixed iteration count or epsilon. Always be mindful of integer overflow when computing midpoints — use the idiom m1 = lo + (hi - lo) / 3 and m2 = hi - (hi - lo) / 3 to avoid overflow.

ternary_search.cppCPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <vector>
#include <algorithm>

template<typename T>
int ternarySearchMax(const std::vector<T>& arr) {
    int lo = 0, hi = arr.size() - 1;
    while (hi - lo > 2) {
        int m1 = lo + (hi - lo) / 3;
        int m2 = hi - (hi - lo) / 3;
        if (arr[m1] < arr[m2])
            lo = m1 + 1;
        else if (arr[m1] > arr[m2])
            hi = m2 - 1;
        else {
            lo = m1 + 1;
            hi = m2 - 1;
        }
    }
    int maxIdx = lo;
    for (int i = lo + 1; i <= hi; ++i)
        if (arr[i] > arr[maxIdx])
            maxIdx = i;
    return maxIdx;
}

int main() {
    std::vector<int> arr = {1, 3, 5, 4, 2};
    std::cout << ternarySearchMax(arr) << std::endl;  // 2
    return 0;
}
Output
2
Production Insight
In C++, beware of signed integer overflow when hi and lo are large (e.g., near INT_MAX). Use long long for indices or ensure the range fits in int. The idiom m1 = lo + (hi - lo) / 3 is safe as long as hi - lo does not overflow.
Key Takeaway
C++ implementation of ternary search is directly analogous to Java and Python. Use templates for generic types and always honor the stop condition hi - lo > 2.

Apply your understanding of ternary search with these curated problems from Codeforces and HackerEarth:

  • [Codeforces 1357B](https://codeforces.com/problemset/problem/1357/B) — Ternary Search (explicit problem to implement the algorithm on a bitonic array)
  • [HackerEarth: Ternary Search](https://www.hackerearth.com/practice/algorithms/searching/ternary-search/tutorial/) — Tutorial with multiple practice problems including Peak Finding
  • [Codeforces 1185C2](https://codeforces.com/problemset/problem/1185/C2) — Exam in BerSU (ternary search on prefix sums)
  • [LeetCode: Find Peak Element (bitonic variant)](https://leetcode.com/problems/find-peak-element/) — Classic problem that can be solved with ternary search or binary search on derivative.

Each problem reinforces the stop-condition nuance, and some require combining ternary search with greedy or prefix sums.

Production Insight
Practicing these problems helps internalize the integer stop condition and the difference between continuous and discrete ternary search. Many production bugs are exactly the kind of mistake that a good practice problem would catch.
Key Takeaway
Master ternary search by solving 3-5 problems from Codeforces and HackerEarth. Focus on integer stop conditions and handling plateaus.
● Production incidentPOST-MORTEMseverity: high

Parameter Tuning Gone Wrong: Ternary Search on a Black-Box Cost Function

Symptom
Model accuracy remained 15% lower than baseline after hyperparameter tuning. Training loss curve showed the learning rate was suboptimal in a region that should have been explored.
Assumption
Ternary search correctly finds the global minimum of any unimodal function.
Root cause
The cost function was not strictly unimodal — it had a small plateau near the true minimum. Ternary search's equality branch treated f(m1)==f(m2) as signalling the extremum lies in the middle third, but the plateau extended beyond that, causing premature convergence to a boundary of the plateau.
Fix
Added a small epsilon tolerance for floating-point comparisons and a fallback to brute-force scanning of the final interval when the function values are very close over multiple iterations.
Key lesson
  • Ternary search assumes strict unimodality — plateaus break it.
  • Always validate the shape of the function before using any extremum-finding algorithm.
  • For production hyperparameter tuning, combine ternary search with random restarts or use golden-section search if function evaluations are expensive.
Production debug guideThree common production symptoms and their root causes3 entries
Symptom · 01
Search returns a value outside the expected range (off-by-one).
Fix
Check that lo and hi are updated correctly — integer versions require lo = m1 + 1 and hi = m2 - 1, not lo = m1 or hi = m2.
Symptom · 02
Search runs forever (infinite loop).
Fix
For integer arrays, verify the loop condition uses 'hi - lo > 2', not '>='. For continuous, ensure the epsilon is large enough to allow termination, and that m1 and m2 are recalculated each iteration.
Symptom · 03
Result is not the true extremum — the function is unimodal but the algorithm gives a wrong answer.
Fix
Reproduce with a small test case. Add print statements for lo, hi, m1, m2, f(m1), f(m2). Verify that the comparison logic matches the goal (max vs min). Also check for integer division truncation when range is 2 or 3.
★ Ternary Search Debug Cheat SheetQuick commands and fixes for the three most common ternary search issues in production.
Infinite loop in integer ternary search
Immediate action
Kill the process and inspect the loop condition.
Commands
echo 'lo=$lo hi=$hi m1=$m1 m2=$m2'
Check that the loop condition is 'while (hi - lo > 2)' and not '>= 2'.
Fix now
Change loop condition to 'while (hi - lo > 2)' and ensure m1 and m2 are recalculated each iteration.
Continuous ternary search terminates too early (incorrect answer)+
Immediate action
Print the current lo, hi, and function values at each iteration.
Commands
for i in $(seq 1 200); do m1=...; m2=...; echo "$i $m1 $m2 $(f($m1)) $(f($m2))"; done
Check if the function is actually unimodal in the final interval by plotting a few points.
Fix now
Increase the number of iterations to 500 or use an epsilon of 1e-12. If plateaus exist, switch to golden-section search.
Ternary Search vs Binary Search vs Golden-Section Search
AlgorithmSearch SpaceIterations (n=10^6)Evals per IterationBest For
Ternary Search AlgorithmUnimodal functionlog1.5(10^6) ≈ 342Simple optimisation with cheap evaluations
Binary Search on DerivativeMonotonic derivativelog2(10^6) ≈ 201Differentiable unimodal functions
Golden-Section SearchUnimodal functionlog1.618(10^6) ≈ 291 (reuses previous)Expensive function evaluations

Key takeaways

1
Ternary search finds extrema of unimodal functions in O(log n) by comparing two interior probe points.
2
Unlike binary search, ternary search does not require a monotone predicate
only a unimodal function.
3
Each iteration eliminates 1/3 of the search range, giving O(log_1.5 n) total iterations.
4
Implement integer and continuous variants separately
the stop conditions are fundamentally different.
5
If function evaluations are expensive, consider golden-section search instead
it reuses evaluations and converges faster.
6
Always validate the unimodality assumption
plateaus and noise will break ternary search silently.

Common mistakes to avoid

4 patterns
×

Not verifying unimodality before applying ternary search

Symptom
Search converges to a local extremum instead of the global extremum, leading to incorrect optimisation results.
Fix
Plot or mathematically confirm that the function increases then decreases (or vice versa) over the entire search interval. If multiple peaks exist, use simulated annealing or grid search.
×

Using integer division incorrectly for m1 and m2

Symptom
Midpoints become equal or the algorithm enters an infinite loop when hi-lo is small.
Fix
Use m1 = lo + (hi - lo) // 3 and m2 = hi - (hi - lo) // 3. Ensure m1 < m2 when hi - lo > 2. Add a debug print to confirm they are distinct.
×

Treating continuous and discrete search identically

Symptom
In continuous search, using integer division or not using an epsilon causes premature termination or infinite loops.
Fix
For continuous functions, use floating-point division and either a fixed iteration count (e.g., 200) or a tolerance comparison (hi - lo < epsilon). Never mix the two implementations.
×

Off-by-one in the equality branch

Symptom
The algorithm incorrectly narrows the range to a subinterval that excludes the extremum.
Fix
When f(m1) == f(m2), the extremum lies strictly between m1 and m2. Set lo = m1 + 1 and hi = m2 - 1 (not lo = m1 and hi = m2). Test with a small array where the maximum is at the middle index.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01JUNIOR
What type of function can ternary search find the maximum of?
Q02SENIOR
How does ternary search differ from binary search?
Q03JUNIOR
What is the time complexity of ternary search?
Q04SENIOR
When would you choose golden-section search over ternary search?
Q01 of 04JUNIOR

What type of function can ternary search find the maximum of?

ANSWER
A unimodal function – one that strictly increases then strictly decreases (for maximum) or strictly decreases then strictly increases (for minimum). The function must have exactly one peak or valley within the search interval. If the function has multiple local extrema, ternary search may converge to the wrong one.
FAQ · 5 QUESTIONS

Frequently Asked Questions

01
When does ternary search apply instead of binary search?
02
Why not just use binary search on the derivative for unimodal functions?
03
Is ternary search faster than binary search?
04
Can ternary search be used on arrays that are not strictly unimodal but have equal values at the peak?
05
How does ternary search compare to gradient descent for optimization?
🔥

That's Searching. Mark it forged?

7 min read · try the examples if you haven't

Previous
Linear Search Algorithm
4 / 8 · Searching
Next
Introduction to Dynamic Programming