Searching and Priority Queues in o(log n) Time:Introduction and Model of Computation
Introduction
In many cases of algorithm design, the comparison-based model of computation is not the obvious choice. In this chapter, we show how to design data structures with very good complexity on a realistic model of computation where keys are regarded as binary strings, each one contained in one or more machine words (registers). This model is sometimes referred to as the RAM model ∗, and it may be argued that it reflects real computers more accurately than the comparison-based model.
In the RAM-model the word length becomes a natural part of the model. A comparison does not necessarily take constant time, on the other hand we may use a larger variety of operations on data. This model allows for comparison-based algorithms to be used but also for algorithms like tries, bucket sort, radix sort etc, which are known to be efficient in practice.
Model of Computation
We use a unit-cost RAM with word size w. In the standard case we assume that the n keys are w-bit keys that can be treated as binary strings or integers, but we may also consider key that occupy multiple words. It should be noted that the assumption that keys can be treated as binary strings or integers also holds for floating-point numbers (cf. IEEE 754 floating-point standard [18, p. 228]).
In the RAM-model, we can use other operations than comparisons, for instance indirect addressing, shifting, bitwise logical operations, and multiplication. Without loss of generality, we assume that w = Ω(log n), since otherwise we could not even fit the number n, or a pointer, into a machine word. (If we can not fit the number n into a constant number of words, the traditional analysis for comparison-based algorithms would also fail.)
Our complexity analysis has two parameters, the number of keys n and the word length w.
In cases where the complexity is expressed only in terms of n, it is supposed to hold for any possible value of w, and vice versa.
For the searching problem, we assume that an ordered set is maintained and that operations like range queries and neighbour queries are supported. We say that we study ordered dictionaries, as defined below.
DEFINITION 39.1 A dictionary is ordered if neighbour queries and range queries are supported at the same cost as member queries (plus the reporting cost), and if the keys can be reported in sorted order in linear time.
Comments
Post a Comment