Get the latest tech news

My Favorite Algorithm: Linear Time Median Finding (2018)


Finding the median in a list seems like a trivial problem, but doing so in linear time turns out to be tricky. In this post I’m going to walk through one of my favorite algorithms, the median-of-medians approach to find the median of a list in deterministic linear time. Although proving that this algorithm runs in linear time is a bit tricky, this post is targeted at readers with only a basic level of algorithmic analysis.

In this post I’m going to walk through one of my favorite algorithms, the median-of-medians approach to find the median of a list in deterministic linear time. Our goal will be to pick a pivot in linear time that removes enough elements in the worst case to provide\(O(n)\) performance when used with quickselect. Now lets return to our original task, finding the worst possible case where our pivot falls as early in the list as possible.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of linear

linear

Photo of favorite algorithm

favorite algorithm

Related news:

News photo

Show HN: Tegon: Open-source alternative to Jira, Linear

News photo

Faer-rs: Linear algebra foundation for Rust

News photo

Zelda producer Eiji Aonuma thinks linear games are "games of the past"