An array is a fundamental and linear data structure that stores items at contiguous locations. Note that in case of C/C++ and Java-Primitive-Arrays, actual elements are stored at contiguous locations. And in case of Python, JS, Java-Non-Primitive, references are stored at contiguous locations. It offers mainly the following advantages over other data structures.
- Random Access : i-th item can be accessed in O(1) Time as we have the base address and every item or reference is of same size.
- Cache Friendliness : Since items / references are stored at contiguous locations, we get the advantage of locality of reference.
Arrays are used to build other data structures like Stack Queue, Deque, Graph, Hash Table, etc. An array is not useful in places where we have operations like insert in the middle, delete from middle and search in a unsorted data.
- Introduction
- Applications
- Arrays in C
- Vector in C++ STL
- Arrays in Java
- ArrayList in Java
- List in Python
- Arrays in C#
- Arrays in JavaScript
- Print Alternates
- Leaders in an array
- Remove Duplicates from Sorted
- Generate all Subarrays
- Reverse an Array
- Rotate an Array
- Zeroes to End
- Min Increments to Make Equal
- Min Cost to Make Size 1
- Duplicate within K Distance
- Make Even Positioned Greater
- Sum of all Subarrays
- Stock Buy and Sell – Multiple Transactions
- Single Among Doubles
- Missing Number
- Missing and Repeating
- Only Repeating from 1 to n-1
- Sorted Subsequence of Size 3
- Max Subarray Sum
- Equilibrium index
- Split array into three equals
- Binary Search
- Selection Sort, Insertion Sort, Binary Search, QuickSort, MergeSort, CycleSort, and HeapSort
- Sort in C++ / Sort in Java / Sort in Python / Sort in JavaScript
- Two Pointers Technique
- Prefix Sum Technique
- Basics of Hashing
- Window Sliding Technique
- Make arr[i] = i
- Maximum Circular Subarray Sum
- Reorder according to given indexes
- Product Except Self
- K-th Largest Sum Subarray
- Smallest subarray with sum greater than x
- Majority Element
- Count possible triangles
- Construct an array from its pair-sums
- Next Permutation
- Surpasser Count
- Trapping Rain Water
- Top K Frequent Elements
- Kth Missing Positive Number in a Sorted Array
- Stock Buy and Sell - At Most K Transactions
- Stock Buy and Sell - At Most 2 Transactions
- Median in a Stream
- Smallest Difference Triplet from 3 arrays
- Max occurred in n ranges
- MO’s Algorithm
- Square Root (Sqrt) Decomposition
- Sparse Table
- Range sum query using Sparse Table
- Range Minimum Query
- Range LCM Queries
- Merge Sort Tree for Range Order Statistics
- Minimum jumps to reach end
- Space optimization using bit manipulations
- Max value of Sum( i*arr[i]) with only rotations
Quick Links :
- Practice Problems on Arrays
- Array Interview Questions
- Quiz on Arrays
- DSA Tutorial