In the 0/1-sorting problem, given a sequence S of elements drawn from a universe E and a characteristic function f : E ! {0,1}, the task is to rearrange the elements in S so that every element x, for which f(x) = 0, is placed before any element y, for which f(y) = 1. Moreover, this reordering should be done stably without altering the relative order of elements having the same f-value, and space efficientlyusing only O(1) words of extra space. In this paper we present a generic algorithm for solving the 0/1-sorting problem which works optimally for many different kinds of sequences and characteristic functions. The model of computation used is a word RAM with a two-level memory hierarchy consisting of an ideal cache and an arbitrarily large main memory. The performance of our algorithm can be summarized as follows: 1. Let n denote the length of S. The algorithm performs at most O(n) element exchanges, invocations of f, and word operations.
更多
查看译文
关键词
characteristic function,model of computation,generic algorithm