⚡ Day 4 Internship • Real World Data Structures

How Apps Use Data Structures

A story-driven interactive visual lab. Master Array, Linked List, Stack, Queue, Tree & HashMap with live animations — then see them powering WhatsApp, Instagram, Swiggy, Amazon and Google Maps.

📦
ArrayO(1) Index
🔗
Linked ListDynamic
StackLIFO
🎯
QueueFIFO
🌳
TreeHierarchy
📜
HashMapO(1) Lookup
Start Here

Why can't we use Array for everything?

Different app features behave differently, so developers choose the right data structure for each problem.

Different problems, different tools

Array is perfect for a marks list, but not the best choice for instant contact search, browser back button, live order processing, or route finding.

Marks ListArray ✓
Browser BackStack ✓
Food OrdersQueue ✓
Contact LookupHashMap ✓
Product CategoriesTree ✓
Google MapsGraph ✓
Scale changes everything
10
records are easy to search manually with a loop.
10M
records need the right data structure to stay fast.

Key insight: “Data Structures are not just theory — they are how apps stay fast at scale.”

Data Structure 1

Array — The Foundation

Elements stored in contiguous memory. Each element has an index starting at 0. Access is instant but inserting in the middle requires shifting.

Interactive Array Demo
Access
Insert
Shift
Click a button to see an array operation
When to use Array?

Use Array when you need fast access by position, or when the data size is fixed.

Access by index: O(1) Instant
Insert/Delete at end: O(1) Fast
Insert/Delete middle: O(n) Slow — shifting!
Search by value: O(n) Linear scan
marks = [85, 92, 78, 95, 88] print(marks[2]) # → 78, O(1) instant! marks.append(91) # O(1) fast marks.insert(2, 100) # O(n) must shift!
Real UsageMarks list, pixel colors, temperatures
Avoid whenFrequent insertions at middle
✍ Array — Live Code Editor
Output appears here after ▶ Run...
arr.access(idx)  ·  arr.append(val)  ·  arr.insert(idx,val)  ·  arr.pop(idx)  ·  arr.reset([...])  ·  print(...)
Data Structure 2

Linked List — Flexible Nodes

Data stored in nodes, each holding a value and a pointer to the next node. No shifting needed for insertion — just update pointers!

Interactive Linked List
3 nodes. Each holds data + pointer to next node.
How Linked List works

No contiguous memory needed. Each node can be anywhere in memory — connected by pointers. Insert/delete at head is O(1) since no shifting!

Insert at head: O(1) Instant
Delete head: O(1) Instant
Access by index: O(n) Must traverse
Search value: O(n) Linear
class Node: def __init__(self, data): self.data = data self.next = None # pointer head → [10|→] → [20|→] → [30|null] # Add at head: O(1), just update HEAD pointer
ArrayFast access O(1), slow insert middle O(n)
Linked ListSlow access O(n), fast insert head O(1)
✍ Linked List — Live Code Editor
Output appears here after ▶ Run...
list.addHead(val)  ·  list.addTail(val)  ·  list.deleteHead()  ·  list.reset([...])  ·  list.size()  ·  print(...)
Data Structure 3

Stack — Last In, First Out (LIFO)

Think of a stack of plates. You always add and remove from the TOP. The last item placed is the first one taken out.

Stack Demo — Browser Back Button
Visit pages (Push), then go Back (Pop)!
LIFO Explained

Last In, First Out. Like a stack of books — you can only take from the top. Whatever you placed last comes out first.

Push (add top): O(1) Instant
Pop (remove top): O(1) Instant
Peek (view top): O(1) Instant
stack = [] stack.append("Google") # Push stack.append("YouTube") # Push stack.append("Instagram") # Push stack.pop() # → "Instagram" (Back!)
Browser BackPages visited
Ctrl+Z UndoText editor
Function CallsCall stack
Brackets Check( ) matching
✍ Stack — Live Code Editor
Output appears here after ▶ Run...
stack.push(val)  ·  stack.pop()  ·  stack.peek()  ·  stack.reset([...])  ·  stack.size()  ·  print(...)
Data Structure 4

Queue — First In, First Out (FIFO)

Think of a queue at a movie theatre. First person in line gets served first. New people join at the rear.

Queue Demo — Food Orders
FRONT (served first) REAR (new orders)
Add orders and serve them to see FIFO!
FIFO Explained

First In, First Out. Whoever comes first gets served first. Fair, orderly, no jumping the queue!

Enqueue (add rear): O(1) Instant
Dequeue (remove front): O(1) Instant
Peek front: O(1) Instant
from collections import deque q = deque() q.append("Order #101") # Enqueue q.append("Order #102") # Enqueue q.popleft() # → "Order #101" served!
Food AppsSwiggy/Zomato orders
WhatsAppMessage delivery
Print QueuePrinter jobs
CPU TasksOS scheduling
✍ Queue — Live Code Editor
Output appears here after ▶ Run...
queue.enqueue(val)  ·  queue.dequeue()  ·  queue.front()  ·  queue.reset([...])  ·  queue.size()  ·  print(...)
Data Structure 5

Tree — Hierarchical Structure

Data organized in parent-child relationships. The top is the Root. A Binary Search Tree (BST) keeps left < root < right, so search is O(log n).

Binary Search Tree Traversal
Click a traversal button to animate visiting each node!
Tree Terms
RootTop node (50)
LeafNo children (20,40,60,80)
HeightLevels from root
BST RuleLeft < Root < Right
Search in BST: O(log n) Very Fast!
Inorder result: Always SORTED!
Inorder: [20,30,40,50,60,70,80] ← sorted! Preorder: [50,30,20,40,70,60,80] ← root first Postorder: [20,40,30,60,80,70,50] ← root last
Real UsageAmazon categories, file system folders, DB index
Why trees?Search O(log n) much faster than list O(n)
✍ Tree — Live Code Editor
Output appears here after ▶ Run...
tree.inorder()  ·  tree.preorder()  ·  tree.postorder()  ·  tree.reset()  ·  print(...)
Data Structure 6

HashMap — Instant Key→Value Lookup

Stores data as key → value pairs. A hash function converts the key to an array index. Lookup is O(1) regardless of data size!

HashMap — Contact Book Demo
Click a contact to look up:
Mom
Rahul
Priya
Boss
Hash
Function
key→index
Hash Table Buckets:
Click a name to see how HashMap finds it instantly!
How HashMap works

HashMap converts your key into a number via a hash function. That number is an array index where the value lives. Finding any value is always O(1) — instant!

Get value by key: O(1) Instant!
Set key-value: O(1) Instant!
Delete by key: O(1) Instant!
vs Array search: O(n) Must scan all!
contacts = {} contacts["Mom"] = "9876543210" contacts["Rahul"] = "9123456789" # Instant O(1) lookup! print(contacts["Mom"]) # → "9876543210" # Array would scan all: O(n) slow!
WhatsAppContacts by name
Instagram@username lookup
DatabaseIndex lookup
CacheURL → response
✍ HashMap — Live Code Editor
Output appears here after ▶ Run...
map.get(key)  ·  map.set(key,val)  ·  map.delete(key)  ·  map.has(key)  ·  print(...)
Real World

Data Structures Inside Real Apps

Every app you use combines multiple data structures. Here's the proof.

WhatsApp

M
Mom
Had lunch?
R
Rahul
Send notes bro
P
Priya
Class link?
G
Internship Group
Day 4 starts now
WhatsApp Data Structures
Contacts → HashMapFind "Mom" instantly O(1)
Recent Chats → Linked ListDynamic list, easy to reorder
Messages → QueueFIFO delivery order
Groups → HashMapGroup ID → members list
contacts["Mom"] → profile O(1) messages.enqueue("Hi") # FIFO chats = LinkedList([Mom, Rahul])

Instagram

A
Arun
Posted a reel
P
Priya
Uploaded photo
R
Rahul
Following Kavya
N
Notifications
3 new likes
Instagram Data Structures
You Rahul Priya Arun Kavya
Profiles → HashMap@username → profile O(1)
Feed → Array/ListScroll post by post
Notifications → QueueFIFO: process in order
Followers → GraphPeople connected (nodes & edges)
Swiggy — Order Queue
Orders → QueueFIFO: first order first served
Restaurant → HashMapFind restaurant O(1)
Menu → TreeFood → Biryani → Chicken
Amazon — Tree Categories
Store Elect. Books Fashion Phone Laptop Men Women
Products → TreeHierarchical categories
Users → HashMapUser ID → details O(1)
Prices → SortingLow to high / high to low
Google Maps — Graph Problem
Chn Blr Hyd Cbe Mys

Cities are nodes. Roads are edges. The shortest route is found using graph algorithms like Dijkstra's or BFS.

Node = City / Person / Location Edge = Road / Follow / Connection Weight = Distance / Time / Cost Path = Route from A to B
Google MapsShortest path
Social NetworkFriend suggestions
DeliveryBest route
Web CrawlGoogle indexing
Algorithm Demo

Sorting — Bubble Sort Visualized

Sorting makes sense when students see exam rankings, product prices and leaderboards.

Use cases: Exam marks ranking, cricket scores, product price low-to-high, YouTube search ranking.

Class Interaction

Quiz — Ask students to answer

Use at end of class to make shy students participate. Click "Show Answer" to reveal.

Q1. Which structure gives O(1) access by position/index?

Q2. Linked List vs Array — which is better for frequent insertions at the head?

Q3. Which structure is best for browser back button?

Q4. Which structure is best for food order processing?

Q5. Which structure helps find contacts instantly by name?

Q6. Which structure represents Amazon product categories?

Q7. Which structure represents Google Maps routes?

Q8. What is the time complexity of searching in a BST?

Final Takeaway

Data Structures are not just coding topics. They are the hidden design behind every modern application.

ArrayO(1) index access
Linked ListO(1) insert head
StackLIFO — Back/Undo
QueueFIFO — Orders
TreeO(log n) search
HashMapO(1) lookup