Hybrid Array List: an Efficient Dynamic Array with Linked List Structure

Hybrid Array List: an Efficient Dynamic Array with Linked List Structure

OPEN ACCESS Ind. Journal on Computing ISSN 2460-9056 Vol. 5, Issue. 3, December 2020. pp. 47-62 socj.telkomuniversity.ac.id/indojc doi:10.34818/indojc.2021.5.3.527 Hybrid Array List: An Efficient Dynamic Array with Linked List Structure Mutaz Rasmi Abu Sara #1, Mohammad F. J. Klaib #2, Masud Hasan #3 # Department of Computer Science, Taibah University, Madina Al Munawarah, Saudi Arabia 1 [email protected] 2 [email protected] 3 [email protected] Abstract In this paper, a novel and efficient dynamic array, called hybrid array list (HAL), has been presented. A HAL H has the structure of a linked list, but each node is an array of size at most 2c, where c is an initial array size provided by the user. As elements are added or deleted in H, it grows or shrinks by the number of nodes as well as by the size of the arrays in the nodes. We consider the operations append, insert and delete as well as a helping operation actual position in H. These operations in worst case run in O(1), O(m+c), O(m+c) and O(m) times, respectively, where m is the number of nodes in H. Worst-case running time of similar operations in standard linked list or array are O(n), where n is the total number of elements. As both m and c are no more than n, theoretically HAL is faster than array and linked list. Experimentally, HAL has been implemented and compared with similar operations in array list of Java and vector of C++. Our results show that HAL can perform substantially better when c is about half of the total number of elements. Keywords: Dynamic array, linked list, data structure, hybrid array list Abstrak Kertas kerja ini akan membentangkan suatu tatasusunan yang baru dan dinamik, dinamakan hybrid array list (HAL). HAL H mempunyai struktur suatu senarai berantai, tetapi setiap nod, paling besar, ialah suatu tatasusunan bersaiz 2c, yang mana c ialah saiz tatasusunan awal yang ditetapkan oleh pengguna. Apabila elemen ditambah atau dihapuskan dalam H, ia akan membesar atau menguncup mengikut bilangan nod dan juga mengikut saiz tatasusunan dalam nod tersebut. Kami mengambilkira operasi append, insert dan delete serta suatu operasi pembantu actual position dalam H. Pada jangkaan terburuk, operasi ini berlari O(1), O(m+c) dan O(m) kali masing-masing, yang mana m adalah bilangan nod dalam H. Kes terburuk masa berlari operasi serupa dalam senarai berantai standad atau tatasusunan adalah O(n), yang mana n ialah jumlah bilangan elemen. Oleh kerana kedua-dua m dan c adalah tidak lebih dari n, maka secara teori HAL adalah lebih laju dari tatasusunan dan senarai berantai. Sebagai eksperimen, kami telah melaksanakan HAL dan membandingkan operasi tersebut dengan operasi serupa dalam senarai tatasusunan JAVA dan vector C++. Keputusan kami adalah HAL menunjukkan prestasi jauh lebih baik apabila c lebih kurang separuh dari jumlah bilangan elemen-elemen. Katakunci: Tatasusunan dinamik, senarai berantai, struktur data, senarai tatasusunan hibrid Received on January, 2020. Accepted on December, 2020 Sara et al. Hybrid Array List... 48 I. INTRODUCTION rray and linked list are two most basic and primitive data structures used in computer programming. Both A of them contain a set of similar items. An array has fixed size and is defined by the user at the beginning of a program. The memory allocated for an array is contiguous in the physical memory of a computer. The elements are stored in sequence in the memory. Once defined, the size of an array cannot be changed. The most important advantage of an array is that its elements can be accessed randomly by their indices in constant time per element. See Fig. 1. On the other hand, a linked list stores element in nodes---one node for each element. A node contains an element as well as a link to the next node (and another link to the previous node if the linked list is a doubly linked list). The memory for each node is allocated dynamically during the run time of a program. Therefore, the memory allocated by a linked list is not contiguous. This is an advantage in the sense that for a large number of elements a large size of contiguous memory is not required (unlike an array). Another advantage of a linked list is that the number of elements is not fixed. As long as there is enough memory, the elements can be added in a linked list. However, accessing elements in a linked list is slower than that in an array. In a linked list, an element must be accessed sequentially after moving from the start node to the destination node. In worst case, this time is linear to the number of elements in a linked list. See Fig. 1 for more detail. Array and linked list also greatly differ in insertion and deletion of elements. In an array, insertion and deletion at specific position is expensive, as elements are to be shifted towards left or right respectively. This can take time linear to the number of elements in the array. In contrast, insertion and deletion are easier and faster in a linked list. A node can be inserted at any position in contestant time by manipulating some fixed number of links of the nodes involved. This is constant per insertion or deletion. There are some other comparisons between array and linked list. Standard textbooks on algorithms and data structures contain chapters on array and linked list with discussion on their relative advantages and disadvantages. Such as, the textbooks [1-5] can be seen for this purpose. A. Dynamic arrays For a long time, researchers are trying to find some data structures that can capture the advantages of both array and linked list. In particular, the effort was made to find a data structure that can access the elements in a Fig. 1. (a) An array. (b) A linked list. (c) A hybrid array list (HAL). Ind. Journal on Computing Vol. 5, Issue. 3, December 2021 49 faster way like an array, and at the same time can maintain variable number of elements like a linked list. The most successful innovation so far is the concept of dynamic array [1, 6-16, 18]. The basic principle of a dynamic array is to create an array of fixed size at the beginning. Then the elements are appended, inserted or deleted as like an array. Because of appends and insertions, at any time if the dynamic array becomes full, a new array is created with an increased size. The elements from the old array is copied to the new array along with the newly appended or inserted element. Then the old array is freed. The factor by which the size of the array is increased can vary. However, the usual value of this factor is 1.125 [14], 1.5 [11, 13, 15, 16] or 2 [1, 6, 12]. Similarly, if the dynamic array size becomes too small because of deletions, a new array is created with smaller size and the elements from the old array, excluding the deleted element, are copied to the new array. Then the old array is freed. Again, the factor by which the array size is reduced can vary like 0.5 [1] or 0.25 [1]. B. Variations of dynamic array It may be difficult to find a non-trivial computer program that does not use an array. However, the use of dynamic array is also becoming more common as the programmers want to get the advantages of variable size of a dynamic array. This can be noticed from the practical point of view. Popular and widely used programming languages such as Java, C++ and Python implement dynamic arrays in their standard library functions. Dynamic array is implemented as array list in Java [11, 17], vector in C++ [12, 15] and list in Python [6, 14]. Their implementations are different based on the factor by which the size of the array is increased, which is 1.5 for Java arraylist [11] and C++ vector [15], and 1.125 for Python list [14]. Various popular software and platforms also use or support dynamic array in their codes, such as Android (because its applications are developed in Java), Facebook [16] and Emacs [18, 19]. Also, theoretically, there are several variations of dynamic arrays. The most basic version of a dynamic array can be found in the textbooks on algorithms and data structures, such as in Cormen et al. [1]. In Cormen et al. [1], the dynamic array is explained as an abstract data type (ADT), called dynamic table. The actual structure of a dynamic table can be an array, or an array-implemented stack, heap, queue or hash table. The table size is initially one. The elements are inserted and deleted into the table. When the table is full (due to the insertions), its size is doubled by allocating a new table, copying the elements from the old table to the new table, and finally freeing up the old table. Similarly, when the empty slots in the table (due to the deletions) are much high, its size is made half by allocating a new table, copying the elements from the old table to the new table, and finally freeing up the old table. The authors in [1] showed that the cost of an insertion or a deletion in a dynamic table take constant amortized time on average. (Please recall that an amortized time is the average time required to perform a sequence of operations over all the operations performed [Page 451 of 1, Page 34 of 5].) Gap buffer [18] is a variation of dynamic array that works well when the insertion and deletion operations are performed close to each other in the array position.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    16 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