Multiplicative binary search explained

Class:Search algorithm
Data:Array
Time:O(log n)
Space:O(1)
Best-Time:O(1)
Average-Time:O(log n)
Optimal:Yes

In computer science, multiplicative binary search is a variationof binary search that uses a specific permutation of keys in an array instead of the sorted order used by regular binarysearch.[1] Multiplicative binary search was first described by Thomas Standish in 1980.This algorithm was originally proposed to simplify the midpoint index calculation on small computers without efficient division or shift operations.On modern hardware, the cache-friendly nature of multiplicative binary search makes it suitable for out-of-core search on block-oriented storage as an alternative to B-trees and B+ trees. For optimal performance, the branching factor of a B-tree or B+-tree must match the block size of the file system that it is stored on. The permutation used by multiplicative binary search places the optimal number of keys in the first (root) block, regardless of block size.

Multiplicative binary search is used by some optimizing compilers to implement switch statements.[2] [3]

Algorithm

Multiplicative binary search operates on a permuted sorted array. Keys are stored in the array in level-order sequence of the corresponding balanced binary search tree.This places the first pivot of a binary search as the first element in the array. The second pivots are placed at the next two positions.

Given an array A of n elements with values A0 ... An−1, and target value T, the following subroutine uses multiplicative binary search to find the index of T in A.

  1. Set i to 0
  2. if in, the search terminates unsuccessful.
  3. if Ai = T, the search is done; return i.
  4. if Ai < T, set i to 2×i + 1 and go to step 2.
  5. if Ai > T, set i to 2×i + 2 and go to step 2.

Notes and References

  1. Book: Standish, Thomas A.. Data Structure Techniques. registration. Addison-Wesley. 1980. Chapter 4.2.2: Ordered Table Search. 136–141. 978-0201072563.
  2. Sayle. Roger A. . A Superoptimizer Analysis of Multiway Branch Code Generation . Proceedings of the GCC Developers' Summit . 17 June 2008 . 103–116 . 4 March 2017.
  3. David A. . Spuler . Compiler Code Generation for Multiway Branch Statements as a Static Search Problem . 94/03 . Department of Computer Science, James Cook University, Australia . January 1994.