Hacker News new | ask | show | jobs
by Fri31Aug 2852 days ago
Why n/2? If the array is, for example, sorted in the reverse order, then there is no monotonous run at all, in which case I believe the algorithm considers each element from the array being a run in itself, giving n runs.
1 comments

Runs can be increasing or decreasing, a reversed array is a single run. Worst case is n/2 because you can always split the array in pairs (if it alternates a high and a low value for example).
Ah I didn't know it also exploited reversed runs. Amazing.