Notes
Notes
1. Introduction
An array is a collection of elements, each identified by an index or key. Arrays store data in
contiguous memory locations.
2. Types of Arrays
• One-Dimensional Array: A single list of elements.
• Multi-Dimensional Array: Arrays of arrays (e.g., 2D array is an array of arrays).
3. Array Representation
• In Memory: Elements are stored sequentially.
• Indexing: The first element is at index 0.
4. Operations on Arrays
• Insertion: Adding an element at a specific position.
• Deletion: Removing an element at a specific index.
• Traversal: Accessing each element in sequence.
• Searching: Finding an element (linear search, binary search).
• Updating: Changing the value of an element at a given index.
5. Advantages
• Constant-time access: Array elements can be accessed in constant time, O(1).
• Memory efficiency: Arrays use a contiguous block of memory.
6. Disadvantages
• Fixed size: The size of an array is fixed at the time of creation.
• Inefficient insertions and deletions: Operations like inserting or deleting elements may be
inefficient as they might require shifting elements.
int main() {
int arr[5] = {10, 20, 30, 40, 50};