    # A note on searching sorted unbalanced three-dimensional arrays

We examine the problem of searching sequentially for a desired real value (a key) within a sorted unbalanced three-dimensional finite real array. This classic problem can be viewed as determining the correct dimensional threshold function from a finite class of such functions within the array, based on sequential queries that take the form of point samples. This note addresses the challenge of constructing algorithms that require the minimum number of queries necessary in the worst case, to search for a given key in arrays that have three dimensions with sizes that are not necessarily equal.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1 Introduction

Searching is one of the most basic, frequent and important operations performed in tasks involving computation. A search is used to decide whether or not a given value (termed a key) is present among a given collection of values. When the search must be performed sequentially (as is assumed throughout in this paper) and repeatedly, obviously it should be carried out as efficiently as possible. The complexity of such a search is completely dependent on how the collection is organized. Clearly, when there is no information available about collection organization, every value must be examined. However, when the collection is already sorted, the search can be conducted in a far more efficient manner. It is well-known that binary [knuth3-1973] and saddleback [dijkstra-1976] search algorithms have the best possible worst-case performance for the sequential search of one-dimensional and of two-dimensional square arrays, respectively. The purpose of this note is to describe a sequential search algorithm for the case of three-dimensional arrays that have sizes that are not necessarily equal. This important search problem occurs in many computation-related fields, including computational biology and image processing [baase-gelder-1999, cosnard-duprat-ferreira-1989, gries-1981, sarnath-he-1992].

Consider a finite real -dimensional array , that is sorted, i.e., satisfies if , and for given, independent, , (so, entries of are nondecreasing along its dimensions). The array can be embedded in the -dimensional space with entry , (one of the minimum entries of ) located at the origin, termed the Southwest (SW) corner and with entry , (one of the maximum entries of ) located at the Northeast (NE) corner.

The purpose of this note is to examine the search of sequentially in order to establish, as efficiently as possible, whether or not a given key is a member of . If is found the search is terminated, as it is assumed throughout that there is no necessity to identify further possible instances of the key. It is assumed here that the comparisons between and the members of must be conducted sequentially. A comparison of and any element returns exactly one of the three following results:

 x a(i1,i2,i3), (3) in which case the entries a(j1,j2,j3) for j1⩽i1, j2⩽i2, and j3⩽i3 can be discarded.

Suppose is an matrix with . Due to its unbalanced dimensions sizes, the array is termed tower. It is assumed from now on that . (Otherwise, a simple algorithm based on applying binary search sequentially to each of the rows of the smallest size of is worst-case optimal.)

We propose the following search algorithm that iteratively searches particular subtowers of smaller sizes after discarding entries of that cannot be . With regard to the SW-to-NE diagonal of any cube of any tower, consider the maximum entry that is less than or equal to the key . We term this entry the pivot of the cube. The proposed algorithm identifies a pivot by applying binary search to the SW-to-NE diagonal of the middle cube of maximum possible volume of the current subtower. Once found, the pivot is used to discard entries of , if possible, using (1) and (3). The remainder of the tower is then divided into three smaller subtowers , and (see Figure 1) and the process is repeated on these subtowers until either

is found or all of the remaining subtowers are one- or two-dimensional subarrays. Binary search is used to explore any remaining vectors and Bird’s method

[bird-2006] is used for any two-dimensional subarrays.

The algorithm proceeds by calling the subroutine MAHL-. The variables and , , in this subroutine, denote the limits of the search area of the original tower at each recursive step; and denote the limits of the current SW-to-NE diagonal; and is the pivot of the current the SW-to-NE diagonal of each cube searched. The logical operator “” in line LABEL:diagonal3dlinha15 indicates that if is found in any of the recursive calls of the algorithm, then the algorithm is teminated.

Lines LABEL:diagonal3dlinha3 through LABEL:diagonal3dlinha13 of the algorithm represent a binary search on the SW-to-NE diagonal, the recursive steps are given in line LABEL:diagonal3dlinha15, and in line LABEL:diagonal3dlinha17 the subroutine 1-2-Method() is called. To simplify the description of the algorithm, we assume that this subroutine performs the searches needed for vectors or two dimensional arrays.