Array Cheatsheet

Arrays

Arrays hold values of the same type at contiguous memory locations. In an array, we're usually concerned about two things - the position/index of an element and the element itself.

Advantages

Disadvantages

Common terms

Things to look out for during interviews

Corner Cases

Time Complexity

Operation Big-O Note
Access O(1)  
Search O(n)  
Search (sorted array) O(log(n))  
Insert O(n) Insertion would require shifting all the subsequent elements to the right by one and that takes O(n)
Insert (at the end) O(1) Special case of insertion where no other element needs to be shifted
Remove O(n) Removal would require shifting all the subsequent elements to the left by one and that takes O(n)
Remove (at the end) O(1) Special case of removal where no other element needs to be

Resource

Array in Data Structure: What is, Arrays Operations [Examples]


Revision #5
Created 17 December 2024 01:49:58 by victor
Updated 29 December 2024 21:43:53 by victor