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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…