A group of related data elements stored at adjacent memory locations is referred to as an array. One of the most basic data structures, it allows for random access to each data element by its index number.
Arrays contain a number of crucial characteristics that make them helpful in a wide range of applications:
An array is typically represented as a block of contiguous memory locations, each of which stores an element of the array. Let us see an array declaration :
int arr[5]={1 , 2 , 3 , 4 , 5};
here,
As mentioned earlier, an array’s data elements are all kept together in the main memory at contiguous locations. The base address, or the address of the first member in main memory, is represented by the array name. The array’s elements are each properly represented by an index. We can define the indexing of an array in the below ways –
Following are the basic operations supported by an array.
Operation | Description |
Traverse | Iterating over every element in the array, this operation applies an operation to each element, such as printing its value. |
Insert | Adds a new element to the array at a specified index. |
Delete | Removes an element from the array at a specified index, shifting the remaining elements to fill the gap left by the deleted element. |
Update | This operation alters the value of an element at a certain index. |
Search | Searches for a specific element in the array either by its index or by its value. |
Time and space complexity of various array operations are described in the following table.
Time Complexity
Operation | Average Case | Worst Case |
---|---|---|
Access | O(1) | O(1) |
Search | O(n) | O(n) |
Insertion | O(n) | O(n) |
Deletion | O(n) | O(n) |
Space Complexity
In array, space complexity for the worst case is O(n).
Note: also read about SQL: Sequence
Please follow me to read my latest post on programming and technology if you like my post.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by πr². Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
Build an autocomplete system that, given a query string s and a set of possible…