An array is a collection of items of the same data type stored at contiguous memory locations. The size of the array is fixed and the memory for an array needs to be allocated before use, the size of an array cannot be increased or decreased dynamically.
dataType arrayName[arraySize];
dataType arrayName[] = {1, 2, 3, 4, ...};
Elements in an array can be accessed using indexes. Suppose an array named arr stores N elements. Indexes in an array are in the range of 0 to N-1.
- Insertion and Deletion in arrays.
O(n)
- Searching an Element.
- Linear Search
O(n)
- Binary Search
O(logn)
- Linear Search
- Reversing an Array.
O(n)
- Rotating an Array.
O(n)
- Sliding Window Technique.
- Sorting an array.
- Bubble
O(n^2)
- Selection
O(n^2)
- Insertion
O(n^2)
- Quick
O(nlogn)
,O(n^2)
- Merge
O(nlogn)
- Bubble
- Dynamic Arrays - Vectors (STL)
- pop()
- push()