Arxiv:1709.08900V4 [Cs.DS] 9 Mar 2021 • Init(V): Set All the Elements of Z to V

Arxiv:1709.08900V4 [Cs.DS] 9 Mar 2021 • Init(V): Set All the Elements of Z to V

In-Place Initializable Arrays Takashi Katoh1 and Keisuke Goto1 1Fujitsu Laboratories Ltd., Kawasaki, Japan., kato:takashi 01@jp:fujitsu:com; goto:keisuke@fujitsu:com Abstract An initializable array is an array that supports the read and write operations for any element and the initialization of the entire array. This paper proposes a simple in-place algorithm to implement an initializable array of length N containing ` 2 O(w) bits entries on the word RAM model with w bits word size, which supports all the operations in constant worst-case time. The algorithm requires N` + 1 bits in total, namely, which requires only 1 extra bit on top of a normal array of length N containing ` bits entries. The time and space complexities are optimal since it was already proven that there is no implementation of an initializable array with no extra bit supporting all the operations in constant worst-case time [Hagerup and Kammer, ISAAC 2017]. Our algorithm significantly improves upon the best algorithm presented in the earlier studies [Navarro, CSUR 2014] which uses N + o(N) extra bits to support all the operations in constant worst-case time. 1 Introduction Arrays are important data structures that support the fundamental read and write operations of any given element in constant worst-case time. Another fundamental operation known as ini- tialization, which writes a given initial value to all the elements of the array, appears frequently in numerous algorithms and programs. Although initialization is naively implemented by lin- ear time write operations, the naive initialization may cause a bottleneck in the applications which use large arrays and frequently require initialization. The issue motivates us to study a fundamental data structure initializable array. An initializable array Z[0 :::N − 1] of length N containing ` bits entries supports the fol- lowing operations: read, write, and initialization. • read(i): Return the value stored in the i-th element of Z. • write(i; v): Set the i-th element of Z to v. arXiv:1709.08900v4 [cs.DS] 9 Mar 2021 • init(v): Set all the elements of Z to v. where i and v are the integers within 0 ≤ i < N and 0 ≤ v < 2`. read(i) and write(i; v) are also denoted by Z[i], Z[i] v, respectively. A normal array is obviously an initializable array since it fundamentally supports the read and write operations in constant worst-case time, and init can be implemented by calling write for all N positions in Θ(N) time. Note that init does not necessarily have to call write N times, and it only has to behave as if it does that. That is, when read(i) is called, it only has to return the initial value v of the last initialization init(v) if write(i; v0) was not called after the last initialization; otherwise, it returns v0 of the last write write(i; v0). We assume the word RAM model with w 2 Ω(log N) bits word size that usual arithmetic and bitwise operations on a word take constant worst-case time, and we also assume that 1 ` 2 O(w). We focus on and evaluate the additional extra space over N` bits because the N` bits space is the trivial lower bound. Moreover, we account only the dynamic values for the space of algorithms, e.g., the space for an initial value or auxiliary arrays. Conversely, we do not account static values that can be embedded into a program, e.g., the space for the length of the array or certain static parameters of algorithms. Initializable arrays have been studied since the 1970s. A folklore algorithm supporting all the operations in constant worst-case time was first mentioned (but not described) in the study by Aho et al. [1, Ex. 2.12]. The complete description was later presented in the studies by Mehlhorn [12, Sec. III.8.1] and Bentley [2, Column 1]. The most technical point of implementing the efficient initializable arrays is how to memorize information whether each element of Z was overwritten after the last initialization. The folklore algorithm memorizes the information by using the chain technique, which represents bi-directional links in two auxiliary arrays. It requires 2`(N +1) extra bits. Navarro [15,16] reduced the space to N +o(N) extra bits without increasing the time complexities. Their algorithm combined the folklore algorithm with a bitmap technique using a bit array B of length N such that B[i] is 1 if and only if the i-th element of the array has been written from the last initialization. The runtime of an algorithm depends on the access frequency to the array, which is the ratio of the number of read and write operations, to the array length. Fredriksson and Kilpel¨ainen[3] measured the runtime performances of several algorithms. According to their computational experiments, the folklore algorithm and Navarro's algorithm present the highest efficiency when the access frequency is low (below 1%), while the bitmap solution and the naive solution present the highest efficiency when the access frequency is within 1{10% and greater than 10%, respec- tively. The construction of ZDD [13] is a good example to demonstrate the effectiveness of the initializable arrays. ZDD is a space-efficient data structure which represents any family of sets and is widely used for various practical applications [14, 17]. Knuth [9, 10] used the folklore algorithm to implement a large hash table in the fast ZDD construction algorithm Simpath.A hash table is used to represent million of nodes of ZDD and is initialized before each step of the algorithm. Initializable arrays realize the efficient initialization of such a large hash table. Our Contributions We propose a simple in-place algorithm for initializable arrays, and we have the following theorem. Theorem 1. There exists an initializable array Z of length N containing ` 2 O(w) bits entries which requires 1 extra bit and supports the operations, read, write, and initalization in constant worst-case time. The algorithm uses a novel in-place chain technique which is nearly identical to the folklore algorithm but works in-place. The time and space complexities are optimal since there is no implementation of an initializable array with no extra bit supporting all the operations in constant worst-case time [7]. Moreover, the algorithm is extremely simple and the pseudo-code of the core idea is written within 80 lines (see Algorithm 1{3). Recent Works Hagerup and Kammer [7], and Loong et al. [11] have also proposed in-place algorithms for initializable arrays recently and independently from us. Hagerup and Kammer's algorithm supports the read/write operations in O(t) worst-case time, the initialization in con- stant worst-case time using extra dN=(w=ct)te bits, where c is a constant value greater than 1, and t is a time and space trade-off parameter within 1 ≤ t ≤ dlog Ne. The in-place algorithm of 1 extra bit space is obtained by setting t = dlog Ne, but the read and write operations take O(log N) worst-case time. Loong et al. proposed two algorithms, both of which use 1 extra bit and support the read/initialization operations in constant worst-case time, and for write, one of which, takes amortized constant time and the other takes constant worst-case expected 2 Algorithms Extra bits init read write Normal array 0 Θ(N) O(1) O(1) Folklore [1, 2, 12] 2`(N + 1) O(1) O(1) O(1) Navarro [15, 16] N + o(N) O(1) O(1) O(1) Hagerup and Kammer [7] dN=(w=ct)te O(1) O(t) O(t) Loong et al. [11] 1 O(1) O(1) amortized/expected O(1) This paper 1 O(1) O(1) O(1) Table 1: Comparison of the time and space complexities between the earlier studies, recent ones but independent from us, and ours. In [7], c > 1 is a constant value and t is a time and space trade off parameter within 1 ≤ t ≤ dlog Ne, and the algorithm requires 1 extra bit when setting t = dlog Ne. Only write by Loong et al. takes amortized time or worst-case expected time, and the other operations take worst-case time. time. Compared to these algorithms, our algorithm is quite simple and runs in optimal time and space. See also Table 1. Several space-efficient algorithms have been proposed based on the preprint version of this paper 1. Kammer and Sajenko [8] have extended our algorithm to implement dynamic initializ- able arrays which can increase and decrease the array size. Hagerup [4,5] used the in-place chain techniques presented in this paper to implement space-efficient choice dictionaries which can re- turn an arbitrary element stored after the initialization. These studies for highly space-efficient data structures were introduced in [6]. Organizations The rest of the paper is organized as follows. Section 2 introduces the folklore algorithm which our algorithm is based on. Section 3 considers a simple problem setting ` ≥ dlog Ne and ` 2 O(w), and proposes in-place algorithm using 2` extra bits for this problem setting. Section 4 considers a more general problem setting ` 2 O(w), and presents the proof of Theorem 1. 2 Folklore Algorithm The folklore algorithm implements an initializable array Z of length N containing ` bits entries for ` ≥ dlog Ne and ` 2 O(w), which supports all the operations in constant worst-case time. The algorithm uses three normal arrays of length N containing ` bits entries, V, F, and T 2, along with two variables of ` bits, an initial value initv and a stack pointer b, and it thus requires 2`(N + 1) extra bits in total.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    12 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us