dsa
Arrays: The OG Data Structure (and Why They Still Matter)
• 4 min read
Arrays explained the way you actually learn them — while learning them yourself.
This DSA series is my learning-in-public journey.
I’m not pretending to be a 10x engineer — I’m learning concepts properly and writing them down so future-me (and you) don’t suffer again.
What Is an Array? (No Fancy Words Yet)
An array is just a collection of items stored next to each other in memory.
That’s it.
No hype. No buzzwords.
Think of it like:
- A row of lockers 🧳
- An egg tray 🥚
- A Netflix playlist (ordered, indexed, sometimes disappointing)
Each item has a position, called an index.
Index: 0 1 2 3 4
Value: [5, 10, 15, 20, 25]
Yes, indexing starts at 0.
Computers decided this long ago and we just live with it.
Real-World Analogy (Includes Suffering)
Imagine you booked 5 adjacent seats in a movie theatre 🎬
Seat numbers:
0 | 1 | 2 | 3 | 4
- Want seat #3? You go directly there. No searching.
- Someone wants to sit between seats #1 and #2?
Everyone after that has to stand up and move 😤
That’s arrays in real life:
- Fast access
- Painful insertions in the middle
Arrays in Python (The Friendly Version)
Python doesn’t expose low-level arrays like C/C++.
Instead, we use lists, which behave like arrays for DSA purposes.
numbers = [10, 20, 30, 40, 50]
You’ll solve 90% of array problems using Python lists.
That’s perfectly fine.
Accessing Elements (Why Arrays Are Loved)
print(numbers[2]) # 30
This is O(1) — instant.
Why? Because arrays calculate the memory address directly instead of searching.
No loop.
No drama.
Just vibes.
Common Operations (Good, Bad, Ugly)
1️⃣ Access — Life Is Good
numbers[0] # O(1)
numbers[4] # O(1)
Direct access is the superpower of arrays.
2️⃣ Insert at the End — Still Okay
numbers.append(60)
This is amortized O(1).
Python secretly allocates extra space ahead of time like:
“What if you add more later?”
Smart move.
3️⃣ Insert in the Middle — Pain Begins
numbers.insert(2, 25)
Time Complexity: O(n)
Why?
Because every element after index 2 must shift right.
Your CPU sighs.
Your algorithm slows.
Your interviewer watches silently.
4️⃣ Deleting Elements — Depends Where
numbers.pop() # O(1)
numbers.pop(2) # O(n)
Deleting from the middle = same shifting pain.
Why Arrays Still Matter (Even With Better Options)
Arrays are foundational.
You’ll see them everywhere:
- Sorting algorithms
- Two pointer problems
- Sliding window patterns
- Prefix sums
- Almost every interview question ever
Arrays are like:
“I’m not perfect, but everything else is built on me.”
Time & Space Complexity (Human Version)
| Operation | Time Complexity |
|---|---|
| Access | O(1) |
| Update | O(1) |
| Insert at end | O(1)* |
| Insert in middle | O(n) |
| Delete | O(n) |
| Search (unsorted) | O(n) |
* amortized — meaning “usually fast, occasionally slow, overall fine”.
Space Complexity
- O(n) — you store
nelements - No hidden magic
- No secret memory leaks
Classic Beginner Mistakes (We All Did These)
❌ Assuming indexing starts at 1
❌ Forgetting bounds (IndexError trauma)
❌ Using arrays where frequent insertions are needed
❌ Overengineering simple problems
Bonus classic:
arr = [[0]] * 3
arr[0][0] = 1
print(arr)
Result:
[[1], [1], [1]]
Pain level: maximum
Meme Break 🧠
Arrays are fast
Until you touch the middle
Then they choose violence
When NOT to Use Arrays
Avoid arrays when:
- Frequent insertions/deletions in the middle
- Size changes constantly
- Fast search + modification is required
That’s when:
- Linked Lists
- Sets
- Hash Maps
enter the chat.
Interview Reality Check
If a problem starts with:
“Given an array…”
They expect you to:
- Use indices smartly
- Minimize extra space
- Recognize patterns (two pointers, sliding window)
Arrays are rarely just arrays in interviews.
TL;DR (Save This)
- Arrays store elements contiguously
- Access is O(1)
- Middle insert/delete is O(n)
- Python lists act like arrays
- Master arrays → DSA becomes easier
Coming Up Next
- Time & Space Complexity (explained like money budgeting)
- Two Pointers Pattern
- Sliding Window (arrays on steroids)
Learning in public. One concept at a time 🚀
Subscribe on Substack
Get the latest posts delivered right to your inbox.
🎉 Thanks! Please check your inbox to confirm.
Comments