DSA · Beginner Guide · Interview Prep
Data Structures Basics Every Beginner Must Know
Quick summary — data structures in one paragraph
A data structure is a way of organizing data in memory so that specific operations are fast. Arrays give instant index access. Linked lists give cheap inserts at the front. Stacks are last-in-first-out. Queues are first-in-first-out. Hash maps give near-instant key lookup. Trees keep data sorted and searchable. Graphs model connections. Learn what each one costs (Big-O) and you'll pick the right one without guessing.
In this guide you will learn:
- What a data structure actually is — with everyday analogies.
- Big-O — how to read complexity without fear.
- Arrays and linked lists — with real Python code.
- Stacks, queues, hash maps — the three you'll use most.
- Trees and graphs — plus interview Q&A and a quiz.
SECTION 01What data structures actually are
A data structure is a way of organizing data in memory so that specific operations — insert, search, delete, traverse — are fast and predictable. The same data can be stored in many ways, and the choice decides whether your program finishes in milliseconds or minutes.
Everyday analogies that actually stick:
| Structure | Real-world analogy | Why the analogy works |
|---|---|---|
| Array | A row of numbered lockers | You know the number, you go straight there |
| Linked list | A treasure hunt | Each clue tells you where the next one is |
| Stack | A pile of plates | Last on, first off |
| Queue | A ticket line | First in, first out |
| Hash map | A dictionary | Look up a word by its spelling |
| Tree | A family tree | Each node has parents and children |
| Graph | A map of cities and roads | Nodes connected by edges |
SECTION 02Big-O — why complexity matters
Big-O describes how an operation's cost grows as the input size n grows. It is not about exact milliseconds — it is about the shape of the curve. Two programs can be identical on 10 items and wildly different on 10 million.
| Notation | Name | Example | n = 1,000 | n = 1,000,000 |
|---|---|---|---|---|
| O(1) | Constant | Array index, hash lookup | 1 | 1 |
| O(log n) | Logarithmic | Binary search, balanced BST | ~10 | ~20 |
| O(n) | Linear | Scan a list | 1,000 | 1,000,000 |
| O(n log n) | Linearithmic | Merge sort, heap sort | ~10,000 | ~20,000,000 |
| O(n²) | Quadratic | Nested loops, bubble sort | 1,000,000 | 10¹² |
SECTION 03Arrays and linked lists
These are the two foundational linear structures — data laid out in a sequence. They differ in how memory is arranged, and that single difference drives every performance trade-off.
Arrays store elements in a contiguous block of memory. Because the computer knows the start address and the size of each element, index access is pure arithmetic — O(1). The cost is insertion and deletion in the middle: everything after the gap must shift, which is O(n).
Linked lists store each element in a node that also holds a pointer to the next node. Inserting at the head is O(1) — just rewire two pointers. But reaching the 500th element means walking 500 links, which is O(n). There is no index math.
# Array — Python's list is a dynamic array
arr = [12, 7, 4, 9, 2]
print(arr[2]) # 4 → O(1) index access
arr.append(5) # O(1) amortised — grows at the end
arr.insert(0, 99) # O(n) — every element shifts right
# Linked list — a minimal node in Python
class Node:
def __init__(self, val):
self.val = val
self.next = None
head = Node(1)
head.next = Node(2)
head.next.next = Node(3)
# Insert at head — O(1)
new = Node(0)
new.next = head
head = new
SECTION 04Stacks, queues, and hash maps
These three cover the majority of day-to-day programming. If you learn only four structures, learn arrays plus these three.
Stack (LIFO) — last in, first out. Push adds to the top, pop removes from the top. Both O(1). Used for undo history, the function call stack, balanced-parentheses checks, and depth-first search.
Queue (FIFO) — first in, first out. Enqueue at the back, dequeue from the front. Both O(1) with the right implementation. Used for printer queues, breadth-first search, task scheduling and message queues.
Hash map — a key-value store. A hash function turns the key into an integer, which maps to a bucket in an array. Average lookup, insert and delete are all O(1). Worst case is O(n) if every key collides into one bucket, but good implementations resize to avoid that. A set is a hash map with keys but no values — perfect for uniqueness and membership tests.
# Stack — LIFO
stack = []
stack.append("a") # push
stack.append("b")
print(stack.pop()) # "b" — last in, first out
# Queue — FIFO (use deque, not list)
from collections import deque
q = deque()
q.append("task1") # enqueue
q.append("task2")
print(q.popleft()) # "task1" — first in, first out
# Hash map — frequency counting
words = ["apple", "banana", "apple", "cherry"]
counts = {}
for w in words:
counts[w] = counts.get(w, 0) + 1
print(counts) # {'apple': 2, 'banana': 1, 'cherry': 1}
# Set — O(1) membership checks
seen = set()
for w in words:
if w in seen:
print("duplicate:", w)
seen.add(w)
list is an array, not a linked
list. For a queue, always use collections.deque —
list.pop(0) is O(n) and silently destroys performance
in loops. This one mistake shows up in almost every beginner codebase.
SECTION 05Trees and graphs
Trees and graphs handle hierarchical and connected data — the shapes that show up in file systems, databases, social networks and maps.
Trees are nodes with children and no cycles. A binary tree has at most two children per node. A binary search tree keeps the left subtree smaller and the right subtree larger, so search is O(log n) when balanced — but degrades to O(n) when skewed. A heap keeps the smallest (or largest) element at the root and powers priority queues. Real uses: file systems, database indexes (B-trees), expression parsing, autocomplete (tries).
Graphs are nodes (vertices) connected by edges — directed or undirected, weighted or unweighted. They're stored as an adjacency list (sparse, memory-efficient) or an adjacency matrix (dense, O(1) edge checks). Traversal is BFS using a queue, or DFS using a stack or recursion. Real uses: social networks, maps, dependency graphs, recommendation engines.
| Structure | Lookup | Insert | Ordered? | Typical use |
|---|---|---|---|---|
| Array | O(1) by index | O(n) in middle | By index | Lists, buffers, matrices |
| Linked list | O(n) | O(1) at head | No | LRU cache, undo chains |
| Stack / Queue | O(n) | O(1) | LIFO / FIFO | Parsing, BFS, scheduling |
| Hash map | O(1) average | O(1) average | No | Counts, caches, indexes |
| Balanced BST | O(log n) | O(log n) | Yes | Range queries, ordered sets |
| Heap | O(1) min/max | O(log n) | Partial | Priority queues, top-K |
| Graph | O(V + E) traversal | O(1) edge | No | Networks, maps, dependencies |
SECTION 06Interview Q&A — data structures
Q1Which data structure should I learn first?
Arrays and hash maps. They cover roughly 80% of real-world code and most entry-level interview questions. Then stacks and queues. Trees and graphs come after — they matter for medium and hard problems, not for your first week.
Q2Do I need to implement them from scratch?
For interviews — yes, the common ones: array, linked list, stack, queue, hash map, BST. Interviewers want to see that you understand the internals. For real projects — no. Use the language's built-in structures. Knowing how they work helps you debug and pick the right one.
Q3Array vs linked list — when do I use which?
Array when you need fast index access and the size is roughly known. Linked list when you insert or delete at the front frequently and never need random access. In practice, arrays win most of the time because of CPU cache locality — contiguous memory is dramatically faster to scan.
Q4Why is hash map lookup called O(1) if collisions exist?
O(1) is the average case with a good hash function and a low load factor. The worst case is O(n) when every key lands in the same bucket. Real implementations — Python's dict, Java's HashMap — resize and rehash to keep buckets short, so the average stays near O(1) in practice.
Q5How much DSA is enough for a first job?
Enough to solve easy and medium problems on arrays, strings, hash maps, two pointers, and basic trees and graphs. That's roughly 100–150 genuinely understood problems — not 500 memorised ones. Depth beats volume every time.
SECTION 07Test yourself — data structures
Five questions. No sign-up.
0 / 5Pick an answer to see why it is right or wrong.
SECTION 08Frequently asked questions
Do I need to be good at maths to learn data structures?
No. You need basic counting and a willingness to reason about growth. Big-O is not calculus — it's comparing how work scales. The maths-heavy parts (proofs, advanced graph theory) only matter if you go deep into research or competitive programming.
Which language should I use to practise DSA?
Whichever language you're most comfortable in. Python is the fastest to write and read. Java and C++ are common in interviews and competitive programming. The concepts are language-agnostic — don't switch languages just to learn DSA.
How long does it take to learn the basics?
About 4–6 weeks of consistent practice to understand arrays, hash maps, stacks, queues and basic trees — enough to solve easy problems. Another 2–3 months to get comfortable with medium problems and graphs. Consistency beats cramming.
Is DSA only for interviews, or useful in real jobs?
Both. Day-to-day jobs use the language's built-in structures, but knowing the trade-offs helps you choose correctly and debug performance issues. Senior engineers routinely spot O(n²) loops in production that a junior missed — that's applied DSA.
What's the single most useful data structure to master first?
The hash map. Frequency counting, deduplication, caching, two-sum style problems, indexes — it shows up everywhere. Learn it right after arrays and you'll solve more problems with less code.
SECTION 09Related reads
Classroom & online · Noida
Build DSA confidence — one structure at a time
Our DSA & Programming tracks cover arrays, hash maps, trees, graphs and interview patterns with live mentorship, real projects and placement support. Start with the foundations — no CS degree required.
₹18,500 · per programme- Hands-on coding labs
- Live mentor support
- 1:1 interview prep
- Weekday & weekend batches




