Content deleted Content added
Mention "Eytzinger binary search". Tag: Reverted |
m Fixed leq, geq operator order |
||
(3 intermediate revisions by 3 users not shown) | |||
Line 11:
|best-time=[[big O notation#Orders of common functions|''O''(1)]]
|average-time=[[big O notation#Orders of common functions|''O''(log ''n'')]]
|optimal=Yes
}}
In [[computer science]], '''multiplicative binary search''' is a variation
of [[binary search algorithm|binary search]] that uses a specific permutation of keys in an array instead of the sorted order used by regular binary
search.<ref>{{cite book|first=Thomas A.|last=Standish|title=Data Structure Techniques|url=https://archive.org/details/datastructuretec0000stan|url-access=registration|publisher=Addison-Wesley|year=1980|chapter=Chapter 4.2.2: Ordered Table Search|pages=[https://archive.org/details/datastructuretec0000stan/page/136 136–141]|isbn=978-0201072563}}</ref>
Line 19 ⟶ 20:
On modern hardware, the [[cache (computing)|cache]]-friendly nature of multiplicative binary search makes it suitable for [[out-of-core]] search on [[Block (data storage)|block-oriented]] storage as an alternative to [[B-tree]]s and [[B+ tree]]s. 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 ([[Tree_(graph_theory)#Rooted_tree|root]]) block, regardless of block size.
Multiplicative binary search is used by some [[optimizing compiler]]s to implement [[switch statement]]s.<ref>{{cite journal |last1=Sayle|first1=Roger A. |title=A Superoptimizer Analysis of Multiway Branch Code Generation |journal=Proceedings of the GCC Developers' Summit |date=17 June 2008 |pages=103–116 |url=https://www.nextmovesoftware.com/technology/SwitchOptimization.pdf |accessdate=4 March 2017}}</ref><ref>{{cite
== Algorithm ==
Multiplicative binary search operates on a permuted sorted array. Keys are stored in the array in a 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 ''A''<sub>0</sub> ... ''A''<sub>''n''−1</sub>, and target value ''T'', the following [[subroutine]] uses a multiplicative binary search to find the index of ''T'' in ''A''.
# Set ''i'' to 0
# if ''i'' ≥ ''n'', the search terminates
# if A<sub>''i''</sub> = ''T'', the search is done; return ''i''.
# if A<sub>''i''</sub>
# if A<sub>''i''</sub>
== See also ==
Line 36 ⟶ 37:
* {{SDlink|Binary search tree}}
* {{SDlink|Binary_tree#Methods_for_storing_binary_trees|Methods for storing binary trees}}
* {{SDlink|Ahnentafel}}
== Citations ==
|