#1India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

DSA · Beginner Guide · Interview Prep

Data Structures Basics Every Beginner Must Know

Arrays, linked lists, stacks, queues, hash maps, trees and graphs — explained without the textbook jargon. What each one is, when to use it, what it costs, and the code you actually write. Start here.

Tracks
Pick a structure · Live Interactive
Structure
—
The container
Best at
—
Its strength
Lookup cost
—
Big-O
Insert → Search → Delete → Traverse
Every structure is a trade-off. The right one makes your code fast; the wrong one makes it crawl. Pick based on the operations you run most.

Home / Tutorials / DSA / Data Structures Basics Every Beginner Must Know

DSA · Beginner Guide · Interview Prep

Data Structures Basics Every Beginner Must Know

ARRAY · O(1) INDEX HASH MAP · O(1) AVERAGE TREE · O(log n) BALANCED 12 7 4 9 2 [0] [1] [2] [3] [4] Contiguous memory. Index math is instant. arr[3] → 9 "name" → "Ankit" "city" → "Noida" "score" → 92 Key hashed → bucket. Lookup is near-instant. 8 4 12 2 6 Left < node < right — keeps data sorted.
Three of the structures you'll use every week — array, hash map, and a binary search tree.

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:

  1. What a data structure actually is — with everyday analogies.
  2. Big-O — how to read complexity without fear.
  3. Arrays and linked lists — with real Python code.
  4. Stacks, queues, hash maps — the three you'll use most.
  5. 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
ArrayA row of numbered lockersYou know the number, you go straight there
Linked listA treasure huntEach clue tells you where the next one is
StackA pile of platesLast on, first off
QueueA ticket lineFirst in, first out
Hash mapA dictionaryLook up a word by its spelling
TreeA family treeEach node has parents and children
GraphA map of cities and roadsNodes connected by edges
Key insight: Data structures are not academic trivia. They are the difference between code that scales and code that crashes when real data shows up. You will not memorise all of them — you will learn when each one is the right tool.

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)ConstantArray index, hash lookup11
O(log n)LogarithmicBinary search, balanced BST~10~20
O(n)LinearScan a list1,0001,000,000
O(n log n)LinearithmicMerge sort, heap sort~10,000~20,000,000
O(n²)QuadraticNested loops, bubble sort1,000,00010¹²
Key insight: The gap between O(n) and O(n²) is not "twice as slow". At a million items it is the difference between a program that finishes and one that times out. This is why interviews ask about complexity — not to test memorisation, but to see if you can predict performance.

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
Key insight: In real projects, arrays win most of the time — CPU caches love contiguous memory, and index access is hard to beat. Linked lists win when you insert and delete at the front constantly (LRU caches, undo chains) and never need random access.

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)
Pro tip: Python's 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
ArrayO(1) by indexO(n) in middleBy indexLists, buffers, matrices
Linked listO(n)O(1) at headNoLRU cache, undo chains
Stack / QueueO(n)O(1)LIFO / FIFOParsing, BFS, scheduling
Hash mapO(1) averageO(1) averageNoCounts, caches, indexes
Balanced BSTO(log n)O(log n)YesRange queries, ordered sets
HeapO(1) min/maxO(log n)PartialPriority queues, top-K
GraphO(V + E) traversalO(1) edgeNoNetworks, maps, dependencies
Key insight: Choose a structure based on the operations you run most — not on what sounds advanced. A hash map beats a tree for pure lookups. A tree beats a hash map when you need sorted order or range queries. A heap beats both when you only need the minimum.

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 / 5

Pick 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.

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 ₹28,000
  • Hands-on coding labs
  • Live mentor support
  • 1:1 interview prep
  • Weekday & weekend batches