0% found this document useful (0 votes)
4 views17 pages

Data Structures Notes

This document is a comprehensive guide on Data Structures using C Language for BCA Semester II, covering five units including Arrays, Stack & Queue, Linked Lists, Trees, and Binary Search Trees. Each unit contains definitions, types, operations, and examples, along with expected exam questions to aid students in their preparation. The content is structured in a way that emphasizes key concepts and practical applications, making it suitable for a crash course before the exam on May 7, 2026.

Uploaded by

spomnight
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views17 pages

Data Structures Notes

This document is a comprehensive guide on Data Structures using C Language for BCA Semester II, covering five units including Arrays, Stack & Queue, Linked Lists, Trees, and Binary Search Trees. Each unit contains definitions, types, operations, and examples, along with expected exam questions to aid students in their preparation. The content is structured in a way that emphasizes key concepts and practical applications, making it suitable for a crash course before the exam on May 7, 2026.

Uploaded by

spomnight
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DATA STRUCTURES

Using C Language

BCA Semester II (NEP) | CCSU Meerut | Code: BCA-2002

Hinglish Crash Course — Exam 7 May 2026

Complete 5 Units + Previous Year Questions

CONTENTS
Unit 1 — Introduction to Data Structures, Arrays

Unit 2 — Stack & Queue

Unit 3 — Linked List

Unit 4 — Trees & Binary Search Tree

Unit 5 — Sorting, Searching & Hashing


UNIT 1: Introduction to Data Structures &
Arrays

1.1 Data Structure Kya Hai?


Data Structure ek tarika hai jisme hum data ko computer memory mein organize, store aur
manage karte hain taaki use efficiently access aur modify kiya ja sake.

Simple Example: Agar tumhare paas 100 students ke marks hain, toh unhe ek jagah
organized rakhna Data Structure hai!

1.2 Types of Data Structures


Type Kya Hai Examples

Basic data types, directly CPU mein store hote


Primitive hain int, float, char, double

Non-Primitive Data ek line mein sequence mein store hota


Linear hai Array, Stack, Queue, Linked List

Non-Primitive
Non-Linear Data hierarchy ya network mein store hota hai Tree, Graph

Static Size compile time pe fix hoti hai Array

Dynamic Size runtime pe change ho sakti hai Linked List, Stack (dynamic)

1.3 Operations on Data Structures


• Traversal: Saare elements ko ek ek karke access karna
• Insertion: Naya element add karna
• Deletion: Element hatana
• Searching: Koi specific element dhundhna
• Sorting: Elements ko order mein lagana (ascending/descending)
• Merging: Do data structures ko combine karna

1.4 Algorithm kya hai?


Algorithm ek step-by-step instructions ka set hai jo kisi problem ko solve karne ke liye likha jata
hai. Isme defined input aur output hota hai.

Properties of a Good Algorithm (yaad karo - FIOD):


✓ Finiteness — Algorithm kabhi bhi khatam honi chahiye
✓ Input — Zero ya zyada inputs lena chahiye
✓ Output — Kam se kam ek output dena chahiye
✓ Definiteness — Har step clearly defined hona chahiye
✓ Effectiveness — Har step simple aur feasible hona chahiye

1.5 Time & Space Complexity


Time Complexity: Algorithm ko complete hone mein kitna time lagta hai — input size ke saath.
Space Complexity: Algorithm ko run karne ke liye kitni memory chahiye.

Notation Name Example Matlab

O(1) Constant Array index access Fastest - size se koi fark nahi

O(log n) Logarithmic Binary Search Bahut fast

O(n) Linear Linear Search Input ke saath badhta hai

O(n log n) Log Linear Merge Sort Theek hai

O(n^2) Quadratic Bubble Sort Slow - avoid karo

1.6 Arrays — Sabse Important!


Array ek same type ke elements ka collection hai jisme elements contiguous memory locations
mein store hote hain. Index 0 se start hota hai.

Declaration:
int arr[5]; // 5 integers ka array
int arr[5] = {10, 20, 30, 40, 50}; // Initialization ke saath

Memory mein Array ka structure:


10 20 30 40 50

arr[0] arr[1] arr[2] arr[3] arr[4]

1000 1002 1004 1006 1008

(Value / Index / Memory Address)

Types of Arrays:
• 1D Array — int a[5] — Ek line mein elements
• 2D Array — int a[3][4] — Matrix jaise — rows aur columns
• Multi-Dimensional — int a[2][3][4] — 3D ya zyada dimensions

2D Array Example (Matrix):


int matrix[2][3] = {{1,2,3},{4,5,6}};
// matrix[0][0]=1, matrix[0][1]=2, matrix[1][2]=6
Advantages of Array:
✓ Random access possible — O(1) mein koi bhi element access karo
✓ Memory efficient — contiguous memory use hoti hai
✓ Easy to implement aur use karna

Disadvantages of Array:
✗ Fixed size — pehle se size decide karni padti hai
✗ Insertion/Deletion slow — O(n) time lagta hai
✗ Agar size chhota padh jaye toh problem hoti hai

UNIT 1 — EXPECTED EXAM QUESTIONS (Most Important!)


■■■ Q: Data Structure kya hai? Uske types explain karo with examples.
■■■ Q: Array kya hai? 1D aur 2D array mein difference batao. Declaration aur initialization likhna.
■■■ Q: Time Complexity kya hai? Big-O notation explain karo.
■■ Q: Algorithm ki properties (characteristics) kya hain? Explain each.
■■ Q: Linear aur Non-Linear data structures mein difference batao.
■■ Q: Static aur Dynamic data structures mein antar karo.
■ Q: Space Complexity kya hai? Example do.
■ Q: Array ke advantages aur disadvantages likhna.

■ TIP: 'Data Structure kya hai + types' aur 'Array ka full explanation' hamesha exam mein
aata hai!
UNIT 2: Stack & Queue

2.1 Stack — LIFO Structure


Stack ek Linear Data Structure hai jisme elements sirf ek end se add aur remove hote hain jise TOP
kehte hain. Yeh LIFO (Last In First Out) principle follow karta hai.

Real Life Example: Plates ki stack — upar wali plate pehle niklegi! Jab bhi koi naya plate aata
hai woh upar rakha jaata hai aur upar se hi nikala jaata hai.

Stack Operations:
Operation Kya Karta Hai Example

PUSH Stack mein element daalna (top pe) Push(5) → Stack: [5]

POP Stack se element nikalna (top se) Pop() → Upar wala nikalta hai

PEEK/TOP Top element dekhna bina nikale Peek() → Top ka value dikhata hai

isEmpty Check karna ki stack khali hai ya nahi Returns True/False

isFull Check karna ki stack full hai ya nahi Sirf array implementation mein

Stack Diagram (Push 10, 20, 30):


30 ← TOP

20

10 ← BOTTOM

Stack using Array (C Code):


#define MAX 5
int stack[MAX], top = -1;

void push(int val) {


if(top == MAX-1) printf('Stack Full!');
else stack[++top] = val;
}

int pop() {
if(top == -1) printf('Stack Empty!');
else return stack[top--];
}

Applications of Stack:
→ Function calls aur recursion (Call Stack)
→ Browser ka Back button
→ Undo/Redo operation in editors
→ Expression evaluation (Infix to Postfix)
→ Syntax checking (brackets matching)
→ Reverse a string

Infix, Prefix, Postfix Expression:


Type Format Example

Infix Operator between operands A+B

Prefix (Polish) Operator before operands +AB

Postfix (Reverse Polish) Operator after operands AB+

2.2 Queue — FIFO Structure


Queue ek Linear Data Structure hai jisme elements ek end se add hote hain (REAR) aur doosre
end se remove hote hain (FRONT). Yeh FIFO (First In First Out) principle follow karta hai.

Real Life Example: Bank mein line — jo pehle aaya woh pehle service pata hai! FRONT se log
nikalte hain, REAR se naye log aate hain.

Queue Diagram:

FRONT → 10 20 30 ← REAR

Queue Operations:
Operation Kaam Time

ENQUEUE REAR se element add karna O(1)

DEQUEUE FRONT se element remove karna O(1)

PEEK/FRONT Front element dekhna O(1)

isEmpty Check if queue empty hai O(1)

Types of Queue:
• Simple Queue: Normal FIFO queue
• Circular Queue: Last position FRONT se connect hoti hai — memory waste nahi hoti
• Double Ended Queue (Deque): Dono ends se insert aur delete possible
• Priority Queue: High priority element pehle process hota hai

Applications of Queue:
→ CPU Scheduling (Round Robin)
→ Printer spooling
→ BFS (Breadth First Search) in graphs
→ Call center phone systems
→ IO Buffers

Stack vs Queue Comparison:


Feature STACK QUEUE

Principle LIFO FIFO

Insert end TOP (ek hi end) REAR

Delete end TOP (ek hi end) FRONT

Real Example Plate stack, Undo Bank line, Printer

Pointer Sirf TOP FRONT aur REAR dono

UNIT 2 — EXPECTED EXAM QUESTIONS


■■■ Q: Stack kya hai? PUSH aur POP operations ko example ke saath explain karo. C code
likhna.
■■■ Q: Queue kya hai? ENQUEUE aur DEQUEUE explain karo with diagram.
■■■ Q: Stack aur Queue mein difference batao (table format mein).
■■■ Q: Infix expression ko Postfix mein convert karo: (A+B)*C-D
■■ Q: Circular Queue kya hai? Aur Normal Queue se kaise alag hai?
■■ Q: Stack ke applications likhna (kam se kam 4).
■■ Q: Priority Queue kya hai? Real life example do.
■ Q: LIFO aur FIFO ka matlab explain karo.

■ TIP: Infix to Postfix conversion ZAROOR aata hai! Stack diagram bana ke likhna.
UNIT 3: Linked List

3.1 Linked List Kya Hai?


Linked List ek Linear Data Structure hai jisme elements (nodes) ek chain mein connected hote hain.
Har node mein 2 parts hote hain: DATA aur NEXT POINTER (agla node ka address).

Real Life Example: Train ke coaches — har coach (node) mein passengers (data) hain aur ek
coupler (pointer) se agle coach se juda hai!

Node Structure in C:
struct Node {
int data; // Data part
struct Node* next; // Pointer to next node
};

Linked List Diagram:

[10|•]→ [20|•]→ [30|•]→ [40|NULL]

HEAD → Node1 → Node2 → Node3 → NULL

3.2 Types of Linked List


Singly Linked List:
Har node mein sirf ek pointer hota hai jo agle node ki taraf point karta hai. Sirf forward direction mein
traverse kar sakte hain.
Structure: 10→20→30→NULL

Doubly Linked List:


Har node mein do pointers hote hain — PREV (pichhle node ka) aur NEXT (agle node ka). Dono
direction mein traverse possible.
Structure: NULL←10⇔20⇔30→NULL

Circular Linked List:


Last node ka pointer NULL ki jagah FIRST node ko point karta hai. Ek circle ban jaata hai.
Structure: 10→20→30→(back to 10)

Doubly Circular Linked List:


Doubly + Circular dono features hain. Last node next FIRST ko point karta hai aur first node prev
LAST ko.
Structure: Complex circular chain
3.3 Operations on Linked List
• Insertion at Beginning: Naya node banao, uska next = HEAD banao, HEAD = naya node
• Insertion at End: Last node tak jao, uska next = naya node banao
• Insertion at Position: Position-1 node tak jao, wahan se naya node connect karo
• Deletion from Beginning: HEAD = HEAD->next karo, purana node delete karo
• Deletion from End: Second last node dhundo, uska next = NULL karo
• Traversal: HEAD se start karke har node ka data print karo jab tak NULL na mile
• Search: Har node ka data check karo jab tak match mile ya NULL aaye

Array vs Linked List:


Feature Array Linked List

Memory Contiguous (ek saath) Non-contiguous (bikhari hui)

Size Fixed (static) Dynamic (change hoti hai)

Access Random O(1) Sequential O(n)

Insertion/Deletion Slow O(n) Fast O(1) at beginning

Memory usage Less (sirf data) More (data + pointer)

Applications of Linked List:


→ Music player — next/previous song
→ Browser history (forward/backward)
→ Undo operation implementation
→ Polynomial addition
→ Memory management in OS
→ Implementation of Stack aur Queue

UNIT 3 — EXPECTED EXAM QUESTIONS


■■■ Q: Linked List kya hai? Node ka structure C mein likho aur diagram banao.
■■■ Q: Singly, Doubly aur Circular Linked List mein antar batao with diagrams.
■■■ Q: Array aur Linked List mein comparison karo (table format).
■■ Q: Singly Linked List mein insertion (beginning, end, position) ka algorithm likho.
■■ Q: Doubly Linked List kya hai? Iske advantages kya hain over Singly?
■■ Q: Linked List ke applications likhna.
■ Q: Circular Linked List kya hai? Diagram ke saath explain karo.
■ Q: Linked List mein deletion ka algorithm likho.

■ TIP: Node structure C mein aana chahiye. Diagram ke saath likhoge toh extra marks
milenge!
UNIT 4: Trees & Binary Search Tree

4.1 Tree kya hai?


Tree ek Non-Linear, Hierarchical Data Structure hai jisme nodes ek parent-child relationship mein
organized hote hain. Ek special node hota hai jise ROOT kehte hain.

Real Life Example: Family tree — Dada (root) ke neeche Papa-Chacha (children), unke neeche
aap log (grandchildren). Ya Company hierarchy!

4.2 Important Tree Terminology:


Term Matlab

Root Sabse upar wala node — parent nahi hota (Example: A)

Node Tree ka har element

Edge Do nodes ko connect karne wali line

Parent Jis node ke neeche doosre nodes hain

Child Jo node kisi doosre node ke neeche ho

Leaf Node Jiske koi children nahi hain (end node)

Siblings Same parent wale nodes

Height of Tree Root se sabse door leaf tak ka distance

Depth of Node Root se us node tak ka distance

Subtree Kisi node aur uske saare descendants ka group

Degree Kisi node ke children ki sankhya

4.3 Binary Tree


Binary Tree mein har node ke maximum 2 children hote hain — Left Child aur Right Child.

Binary Tree Diagram:


A (Root)

B (Left) C (Right)

DE FG

Types of Binary Tree:


• Full Binary Tree: Har node ke exactly 0 ya 2 children hain
• Complete Binary Tree: Saare levels filled hain, last level left se fill hoti hai
• Perfect Binary Tree: Saare leaf nodes same level pe hain
• Skewed Binary Tree: Saare nodes ek side (left ya right) mein hain

4.4 Tree Traversals — MOST IMPORTANT! ■■■

Traversal matlab hai tree ke saare nodes ko ek specific order mein visit karna. Teen main types
hain.

Traversal Order Trick Result (A,B,D,E,C,F)

INORDER Left → Root → Right LNR DBEAFC

PREORDER Root → Left → Right NLR ABDECF

POSTORDER Left → Right → Root LRN DEBFCA

■ TRICK to remember: In-Order=LNR, Pre-Order=NLR, Post-Order=LRN (L=Left,


N=Node/Root, R=Right)

4.5 Binary Search Tree (BST) — EXAM FAVOURITE!


BST ek special Binary Tree hai jisme ek important rule hai:

BST RULE: Left Child < Parent < Right Child

BST Example — Insert: 50, 30, 70, 20, 40, 60, 80


50 (Root)
/ \
30 70
/ \ / \
20 40 60 80 (Leaf nodes)

Inorder of BST = 20, 30, 40, 50, 60, 70, 80 (ALWAYS SORTED! ■)

BST Operations:
• Search: Root se compare karo — chhota hai toh left jao, bada hai toh right jao. O(log n)
• Insert: Search karo sahi position, wahan naya node banao
• Delete (3 cases): 1) Leaf node: seedha delete karo 2) 1 child: child ko uski jagah do 3) 2
children: Inorder successor se replace karo

Applications of Trees:
→ File system (folders aur files)
→ HTML/XML DOM structure
→ Database indexing (B-Tree)
→ Decision trees in AI/ML
→ Expression trees in compilers
→ Routing tables in networks

UNIT 4 — EXPECTED EXAM QUESTIONS


■■■ Q: Tree kya hai? Tree ki important terminology explain karo (Root, Leaf, Height, Degree,
etc.)
■■■ Q: Binary Tree Traversals — Inorder, Preorder, Postorder example ke saath likhna.
■■■ Q: BST kya hai? Insert karo: 45, 15, 79, 90, 10, 55, 12, 20, 50. BST banao aur traversals
likhna.
■■■ Q: BST mein Search aur Insertion ka algorithm likhna.
■■ Q: Binary Tree ke types explain karo (Full, Complete, Perfect, Skewed).
■■ Q: BST mein deletion ke teen cases explain karo with examples.
■■ Q: Inorder traversal of BST hamesha sorted kyun hota hai? Explain karo.
■ Q: Tree aur Graph mein antar batao.

■ TIP: BST banao diagram mein aur teeno traversals ZAROOR likhna — guaranteed
marks!
UNIT 5: Sorting, Searching & Hashing

5.1 Sorting Kya Hai?


Sorting matlab hai elements ko ek defined order mein arrange karna — ya toh Ascending (chhote
se bade) ya Descending (bade se chhote).

5.1.1 Bubble Sort — Sabse Simple!


Adjacent elements ko compare karo aur agar galat order mein hain toh swap karo. Sabse bada
element 'bubble up' karke end mein pahunch jaata hai.

Example: Sort [64, 34, 25, 12, 22]


Pass 1: [34,25,12,22,64] — 64 end pe aa gaya
Pass 2: [25,12,22,34,64] — 34 sahi jagah
Pass 3: [12,22,25,34,64] — Done!

C Code for Bubble Sort:


for(i=0; i<n-1; i++) {
for(j=0; j<n-i-1; j++) {
if(arr[j] > arr[j+1]) {
// Swap
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}

5.1.2 Selection Sort


Har pass mein unsorted portion ka minimum element dhundho aur use sahi position pe place karo.

Example: [64, 25, 12, 22, 11]


Pass 1: Min=11, Swap with 64 → [11, 25, 12, 22, 64]
Pass 2: Min=12, Swap with 25 → [11, 12, 25, 22, 64]
Pass 3: Min=22, Swap with 25 → [11, 12, 22, 25, 64]
Pass 4: Already sorted → [11, 12, 22, 25, 64] Done!

5.1.3 Insertion Sort


Har element ko sorted portion mein sahi jagah insert karo. Jaise taash ke patte sort karte hain!

Example: [12, 11, 13, 5, 6]


Start: [12] | 11<12, insert left → [11,12]
Next: [11,12] | 13>12, insert right → [11,12,13]
Next: 5 smallest, insert left → [5,11,12,13]
Final: 6 between 5,11 → [5,6,11,12,13] Done!

5.1.4 Merge Sort


Divide and Conquer approach — Array ko aadha-aadha divide karo jab tak single elements na rah
jayein, phir sorted order mein merge karo.
Example: [38, 27, 43, 3]
Divide: [38,27] | [43,3]
Divide: [38] [27] | [43] [3]
Merge: [27,38] | [3,43]
Merge: [3,27,38,43] DONE!

5.1.5 Quick Sort


Divide and Conquer — Ek PIVOT element choose karo. Usse chhote left mein, bade right mein.
Recursively repeat karo.
Example: [10, 80, 30, 90, 40, 50, 70], Pivot=70
Left of 70: [10,30,40,50] | Right: [80,90]
Recursively sort both sides.

Sorting Algorithms Comparison Table:


Algorithm Best Case Average Case Worst Case Space Stable?

Bubble Sort O(n) O(n^2) O(n^2) O(1) Yes

Selection Sort O(n^2) O(n^2) O(n^2) O(1) No

Insertion Sort O(n) O(n^2) O(n^2) O(1) Yes

Merge Sort O(n log n) O(n log n) O(n log n) O(n) Yes

Quick Sort O(n log n) O(n log n) O(n^2) O(log n) No

5.2 Searching
5.2.1 Linear Search
Array ke har element ko ek ek karke check karo jab tak target mile ya array khatam ho jaye.
Time: O(n) | Works on: Unsorted aur Sorted dono arrays
Example: Search 30 in [10,20,30,40,50]
Check 10? No. Check 20? No. Check 30? YES! Found at index 2.

5.2.2 Binary Search — Fast!


Sirf sorted array mein kaam karta hai. Middle element se compare karo — target chhota toh left half,
bada toh right half mein search karo.
Time: O(log n) | Works on: ONLY Sorted arrays
Example: Search 23 in [2,3,4,10,23,40,50]
low=0, high=6, mid=3 → arr[3]=10 < 23, search right
low=4, high=6, mid=5 → arr[5]=40 > 23, search left
low=4, high=4, mid=4 → arr[4]=23 = 23. FOUND!

Linear vs Binary Search:


Feature Linear Search Binary Search

Array type Any (sorted/unsorted) Only SORTED

Time Complexity O(n) O(log n)

Speed Slow for large data Very fast

Method Sequential checking Divide and compare

5.3 Hashing
Hashing ek technique hai jisme ek Hash Function use karke data ko directly ek specific location
(bucket) mein store kiya jaata hai. Isse searching bahut fast hoti hai — O(1)!

Hash Function:
h(key) = key % table_size (Most common — Division Method)
Example: Keys = [12, 25, 35, 40, 52], Table size = 10
12%10=2, 25%10=5, 35%10=5 (COLLISION!), 40%10=0, 52%10=2 (COLLISION!)

Collision kya hai?


Jab do alag keys ka hash value same location pe aata hai toh Collision hoti hai.

Collision Resolution Techniques:


• Chaining (Open Hashing): Same index pe ek Linked List banao — saare colliding elements
wahan store karo
• Linear Probing: Agar location full hai toh next empty location dhundo (index+1, index+2...)
• Quadratic Probing: Linear probing jaisa but step size quadratic hota hai (1, 4, 9, 16...)
• Double Hashing: Doosra hash function use karo step size ke liye

Hash Table Advantages: O(1) average search, insert, delete. Very fast!

Hash Table Disadvantages: Collision handling complexity, extra memory needed.

UNIT 5 — EXPECTED EXAM QUESTIONS


■■■ Q: Bubble Sort kya hai? [64,34,25,12,22] ko sort karo step by step.
■■■ Q: Binary Search kya hai? Example ke saath explain karo. Linear vs Binary comparison
likhna.
■■■ Q: Hashing kya hai? Collision kya hoti hai? Collision resolution techniques explain karo.
■■■ Q: Sorting algorithms ka comparison table likhna (Time complexity ke saath).
■■ Q: Selection Sort aur Insertion Sort explain karo with examples.
■■ Q: Merge Sort ka algorithm likhna aur [38,27,43,3,9,82,10] sort karo.
■■ Q: Quick Sort kya hai? Pivot element ki role explain karo.
■■ Q: Hash Function kya hai? Division method se example solve karo.
■ Q: Linear Probing aur Chaining mein difference batao.
■ Q: Stable aur Unstable sorting algorithms mein kya fark hai?

■ TIP: Bubble Sort step-by-step aur Binary Search example ZAROOR practice karo.
Hashing mein collision resolution types yaad karo!
QUICK REVISION — Last Minute Cheats!

Term Yaad Karo

LIFO Stack — Last In First Out

FIFO Queue — First In First Out

BST Rule Left < Root < Right

Inorder BST ALWAYS gives SORTED output

Binary Search Only on SORTED arrays — O(log n)

Bubble Sort O(n^2) worst, O(n) best (already sorted)

Merge Sort Always O(n log n) — best sorting algo

Hashing O(1) average search using hash function

Array Access Random access O(1) using index

Linked List Dynamic size, Sequential access O(n)

Tree Height Root to farthest leaf ka distance

Degree Number of children of a node

LNR Inorder Traversal — Left Node Right

NLR Preorder Traversal — Node Left Right

LRN Postorder Traversal — Left Right Node

ALL THE BEST FOR YOUR EXAM! Tu kar lega! Mehnat ka fal zaroor
milta hai ■

You might also like