Array Data Structures

Sunidhi Singhal
Thrive in AI
Published in
2 min readFeb 28, 2022

An array is a data structure where data is stored sequentially. Sequential means that each element is stored right after the previous one in the memory.

Let us understand this with the help of memory canvas. Suppose we have a 32-bit system, where we require 4 bytes for storing each individual element. If we have an array: item = [5,6,7], each element will take 4 bytes of space. The total space acquired by a 32-bit system would be 12 bytes or 12 memory slots, starting from 201 to 212(refer below figure). The memory is allocated back to back.

If the size of an array is really big and memory is low, it is impossible to find the memory space to fit the entire array. However, on the other side, the arrays are very fast to access and operate as there is no need to switch between different memory locations.

There are two types of Array: Static(Fixed number of memory slots) and Dynamic(Flexible number of memory slots).

After understanding the fundamentals, one should be knowing below complexities(worst case) of different array operations.

Accessing an Element of Array : O(1)
Searching for an Element in Array : O(n)
Inserting an Element in Array : O(n)
Deleting an Element in Array : O(n)

Thanks for reading.You can ask doubts in the comments.Happy Coding!

--

--