QA
Dashboard

Arrays in dsa

Arrays are contiguous memory blocks holding elements of the same type. They offer O(1) time complexity for access by index. Insertions and deletions at the end are O(1), but in the middle they are O(N) due to element shifting.

Example

const arr = [1, 2, 3, 4];
arr.push(5); // O(1)
arr.splice(1, 0, 10); // O(N)

Arrays are the foundation for many algorithms due to their fast random access.