WIPIVERSE All articles

Funnelsort

Funnelsort is a cache-oblivious sorting algorithm designed to achieve optimal performance across multiple levels of a memory hierarchy without requiring explicit knowledge of cache parameters (such as cache size or block size). It was introduced by Matteo Frigo, Charles E. Leiserson, Harald Prokop, and Sridhar Ramachandran in their 1999 paper "Cache-Oblivious Algorithms" (published at the 40th Annual Symposium on Foundations of Computer Science).

Algorithmic Structure Funnelsort is a variant of merge sort that replaces the standard linear-time merge step with a cache-oblivious merging mechanism called a k-funnel. The algorithm operates recursively:

  1. Divide: The input array of size $N$ is divided into $N^{1/3}$ subarrays, each of size $N^{2/3}$.
  2. Conquer: Each subarray is sorted recursively using Funnelsort.
  3. Merge: The $N^{1/3}$ sorted subarrays are merged using an $N^{1/3}$-funnel.

The k-Funnel A $k$-funnel is a recursive data structure that merges $k$ sorted sequences. It consists of:

  • $k$ input buffers (one for each sequence).
  • A single output buffer.
  • $\sqrt{k}$ "middle" buffers.
  • $\sqrt{k}$ $\sqrt{k}$-funnels connecting the inputs to the middle buffers.
  • One $\sqrt{k}$-funnel connecting the middle buffers to the output.

The funnel operates by recursively filling its output buffer. When the output buffer is empty, the funnel invokes the merger funnel to fill it. When an input buffer to a sub-funnel is exhausted, the funnel recursively refills that buffer from its source.

Complexity Analysis In the cache-oblivious model (ideal cache model with cache size $Z$ and block size $B$), assuming the "tall cache" assumption ($Z = \Omega(B^2)$):

  • Work Complexity: $O(N \log N)$ comparisons, matching the optimal comparison-based sorting bound.
  • Cache Complexity: $O\left(1 + \frac{N}{B} \log_Z N\right)$ memory transfers (cache misses). This matches the lower bound for sorting in the external memory model, making it asymptotically optimal for a cache-oblivious algorithm.

Space Complexity The algorithm requires $O(N)$ auxiliary space for the buffers used during the merge phase. The recursion depth is $O(\log \log N)$ for the funnel structure, contributing negligible stack space.

Significance Funnelsort was the first cache-oblivious sorting algorithm to achieve the optimal $O\left(\frac{N}{B} \log_Z N\right)$ cache complexity. It demonstrated that cache-oblivious algorithms could match the asymptotic performance of cache-aware algorithms (like external merge sort) without hardware-specific tuning. It remains a fundamental result in the theory of cache-oblivious algorithms and is often cited in literature regarding hierarchical memory optimization.

Browse

More topics to explore

    Browse all articles