Stage 4 · Lesson 2 of 10
Arrays and dynamic arrays
An stores items side by side in memory, in one contiguous block. That is why reading or writing any index is O(1): the address is just the start plus the index times the item size. The cost is that inserting or deleting in the middle shifts everything after it, which is O(n).
The list type you already use (Python list, JavaScript array, Java , C++ vector, C# List) is a dynamic array. When it is full, it grabs a bigger block of memory, typically 1.5 to 2 times larger, and copies everything across. That copy is rare enough that appending at the end is O(1) on average, which is called . Removing from the front, though, is O(n) every time, a common hidden cost.
A question to check yourself, an AI practice session and 1 cheat sheet entry come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Data Structures & Algorithms for Coding Interviews
Design Gurus · Beginner · Subscription
Each structure built from first principles, with solutions in Python, Java, C++, JavaScript and C#
- CourseFreeCS50: Introduction to Computer Science
Harvard University · Beginner
Free: weeks 3 and 5 cover searching, sorting, linked lists, hash tables and trees
Practise
Keep handy
Also worth your time
Time and space complexity worked through five common algorithms