Mastery Points
0
Arrays Fundamental in dsa
Context & Logic
Arrays are contiguous memory blocks storing elements. They offer O(1) access by index but O(n) for insertion/deletion (worst case).
Example
const arr = [10, 20, 30];
console.log(arr[1]); // Access: O(1)
arr.push(40); // Insert end: O(1)
arr.splice(1, 0, 15); // Insert middle: O(n)Step-by-Step Logic
1
Traversal: One loop to visit every element (O(n)).
2
Linear Search: Compare each element with the target.
3
Deletion: Find element, shift subsequent elements left.
4
Insertion: Shift elements right to create space, then insert.
Complexity Metrics
Time Efficiency
Access: O(1), Search/Insertion: O(n)
Memory Footprint
O(n) for storage