Data Structure Basics for Class XI
Data Structure Basics for Class XI
Simply put, a Data Structure is a technique for storing and arranging data.
Types of Data Structure
Data Structures are mainly of two types:
1. Linear Data Structure:
•Definition: This is a Data Structure where data elements are arranged in
a sequential or consecutive manner and each element is connected to its
immediate previous and next element.
•The data elements exist at a single level in this structure.
•It's possible to traverse all elements in a single run.
•Fixed Size: The size of an Array must be specified when it is created. Once the size is
determined, it usually cannot be changed at run-time.
•Linear Data Structure: An Array is a linear data structure where elements are arranged in
a sequential order.
Advantages of Array
The main advantages of using an Array in a Data Structure are:
•Fast Access: Since elements are stored sequentially in memory and their index is known, any
element can be accessed directly.
•Efficient Memory Utilization: Data in an Array is stored in contiguous memory blocks and
does not require additional pointers or references like a Linked List, thus allowing for efficient
memory utilization.
•Foundation for Other Data Structures: Arrays are used as the foundation for implementing
many complex data structures like Stack, Queue, Hash Table, etc..
Node: Each element of a Linked List is called a Node. Each Node is divided into two main parts:
[Link]: This is the actual information or value you want to store.
[Link]/Link (Next): This holds the memory address of the next node. Nodes are connected to
each other through this pointer. The Pointer of the last node contains a NULL value, which
indicates the end of the list.
Key Characteristics
•LIFO (Last-In, First-Out): The element that was added most recently is the element that will be removed first.
•Single End Access: All insertions and deletions are done from only one end, called the Top.
•Linear Data Structure: Elements are arranged in a sequential manner.
Operations on a Stack
A stack primarily supports two main operations:
[Link] (Insertion):
1. Adds an element to the top of the stack.
2. If the stack is already full, it results in a condition called Stack Overflow.
[Link] (Deletion):
1. Removes the element from the top of the stack.
2. If the stack is already empty, it results in a condition called Stack Underflow.
Auxiliary Operations
•Peek/Top: Returns the top element of the stack without removing it.
•isEmpty: Checks if the stack is empty.
•isFull: Checks if the stack is full (especially when implemented using an Array).
Applications
Stacks are widely used in computer science for:
•Function Calls/Recursion: The Call Stack manages function calls by storing return addresses and
local variables (LIFO is essential here).
•Expression Evaluation: Used to convert and evaluate arithmetic expressions (Infix to Postfix/Prefix,
and Postfix evaluation).
•Backtracking: Used in algorithms like depth-first search (DFS) to remember the path to return to.
•Browser History: The "Back" button functionality is typically implemented using a stack.
A Queue is a fundamental Linear Data Structure that follows a specific order for operations: FIFO (First-In,
First-Out).
It operates much like a real-world queue or waiting line, such as people waiting to buy tickets or cars waiting at a
traffic light. The element that gets added first is the one that is served and removed first.
Key Characteristics
•FIFO (First-In, First-Out): The element that was added earliest is the element that will be removed first.
•Dual-End Access: Operations occur at two different ends:
• Front (or Head): Where elements are deleted (dequeue).
• Rear (or Tail): Where elements are inserted (enqueue).
•Linear Data Structure: Elements are arranged in a sequential manner.
Operations on a Queue
A queue primarily supports two main operations:
[Link] (Insertion):
1. Adds a new element to the Rear end of the queue.
2. If the queue is full, it results in a Queue Overflow.
[Link] (Deletion):
1. Removes the element from the Front end of the queue.
2. If the queue is empty, it results in a Queue Underflow.
Auxiliary Operations
•Peek/Front: Returns the element at the Front of the queue without removing it.
•Rear: Returns the element at the Rear of the queue without removing it.
•isEmpty: Checks if the queue contains any elements.
•isFull: Checks if the queue has reached its maximum capacity (when array-implemented).
Applications
Queues are essential in operating systems and networking for managing processes and data flow:
•Operating Systems: Managing processes for the CPU (Job Scheduling), handling I/O operations
(print queues), and buffering data.
•Networking: Handling data packets in routers and switches.
•Simulation: Modeling real-world scenarios, like waiting times at a counter.
•Breadth-First Search (BFS): A graph traversal algorithm uses a queue to explore nodes level by
level.
Feature Stack Queue
Principle LIFO (Last-In, First-Out) FIFO (First-In, First-Out)
The last element added is the The first element added is the
Definition
first one to be removed. first one to be removed.
Operation Name for
Push (Insertion) Enqueue (Insertion)
Insertion
Operation Name for
Pop (Deletion) Dequeue (Deletion)
Deletion
Access occurs at two ends: Rear
Access occurs at only one end,
Access Ends (for insertion) and Front (for
called the Top.
deletion).
Elements are added at the Rear
Insertion Location Elements are added at the Top.
(or Tail).
Elements are removed from the Elements are removed from the
Deletion Location
Top. Front (or Head).
A stack of plates or an 'Undo' A waiting line of people or a
Analogy
history. print queue.
Job scheduling in Operating
Function call management (Call
Common Systems (CPU scheduling), and
Stack), expression evaluation,
Application the Breadth-First Search (BFS)
and backtracking algorithms.
algorithm.
1. Simple Queue (or Linear Queue)
•Structure: Elements are inserted at the rear and deleted from the front.
•Order: FIFO (First In, First Out)
•Limitation: When elements are deleted, the freed space at the front can’t be reused
easily.
Example:
Front → [10, 20, 30, 40] ← Rear
After deleting 10 → [20, 30, 40], but front moves forward — not reusable in a static
array.
Use case: Simple task scheduling where reusability of space is not a concern.
2. Circular Queue
•Improvement over Linear Queue
•The last position is connected to the first to form a circle.
•Advantage: Avoids wasted space — can reuse freed positions.
Example:
[10, 20, 30, 40]
Front = 0 → 10
Rear = 3 → 40
If we dequeue 10 and enqueue 50, 50 goes to position 0 (circularly)
Use case: Circular resource management (e.g., CPU scheduling).
3. Double-Ended Queue (Deque)
•Elements can be inserted or removed from both ends.
•Types:
• Input-restricted deque: Insertion allowed only at one end.
• Output-restricted deque: Deletion allowed only at one end.
Example:
Front ⇄ [10, 20, 30, 40] ⇄ Rear
Use case: Implementing both stacks and queues; useful in algorithms like palindrome checking or
sliding window problems.
4. Priority Queue
•Each element is assigned a priority.
•Elements with higher priority are served first, regardless of insertion order.
•Can be implemented using a heap, array, or linked list.
Example:
[ (A, 2), (B, 1), (C, 3) ]
→ Dequeue order: C (3), A (2), B (1)
Use case: Operating systems (process scheduling), Dijkstra’s algorithm,
Huffman coding.
1. Tree Data Structure
A Tree is a hierarchical non-linear data structure that
consists of nodes connected by edges.
Term Meaning
Node Each element in the tree
Root The topmost node (starting point)
Parent A node that has child nodes
Child A node that descends from another node
Leaf A node with no children
Edge Connection between two nodes
Level Distance from the root node
Subtree A smaller tree within the main tree
➢ Structure Example
A •A → Root
/\ •B, C → Children of A
B C •D, E → Children of B
/ \ \ •F → Child of C
D E F •D, E, F → Leaf nodes
Tree Type Description
General Tree No restriction on the number of children.
Binary Tree Each node has ≤ 2 children.
Binary Search Tree
Left < Parent < Right.
(BST)
AVL Tree Self-balancing BST.
Heap (Min/Max) Complete tree used for priority queues.
B-Tree / B+ Tree Multi-way search tree used in databases.
Trie (Prefix Tree) Used for string searching and auto-completion.
➢ Applications
•File systems (folders & subfolders)
•Hierarchical databases
•Binary search (BST)
•Expression evaluation (syntax trees)
•Huffman coding (data compression)
2. Graph Data Structure
A Graph is a non-linear data structure consisting of a set of
vertices (nodes) and edges (connections) between them.
Term Meaning
Vertex (Node) Represents an entity (like a city or person).
Edge Connection between two vertices.
Degree Number of edges incident on a vertex.
Path Sequence of vertices connected by edges.
Cycle Path that starts and ends at the same vertex.
Connected
Every vertex is reachable from another.
Graph
A --- B
| / | •Vertices: A, B, C, D
| / | •Edges: AB, AC, BC, BD, CD
C --- D
Type Description
Directed Graph
Edges have direction (A → B).
(Digraph)
Weighted Graph Each edge has a weight (distance, cost).
➢ Applications
•Social networks (friends, followers)
•Google Maps (shortest path between cities)
•Computer networks (routing)
•Dependency resolution (e.g., build systems)
•Recommendation systems (graph-based relationships)
Recursion
Definition
Recursion is a programming technique in which a function calls itself directly or
indirectly to solve a problem.
In recursion, a problem is divided into smaller subproblems of the same type
until it reaches a simple base case, which can be solved directly.
Limitation Explanation
Each recursive call adds a new frame to the call
1. High Memory Usage
stack, consuming memory.
Too many recursive calls can exceed stack size and
2. Stack Overflow Risk
crash the program.
Function call overhead (saving and restoring stack
3. Slower Execution
frames) makes recursion slower than iteration.
➢ Searching Algorithms (Linear Search & Binary Search)
Searching algorithms are used to find the location (index) of a target value in a list or array.
Two of the most common searching techniques are:
[Link] Search
[Link] Search
Advantages
•Much faster than Linear Search
•Efficient for large datasets
•Uses divide-and-conquer
Disadvantages
•Array must be sorted
•Not suitable for frequently updated lists (sorting cost)
Python Code
return -1
Bubble Sort Algorithm
➢ Definition
Bubble Sort is a simple comparison-based sorting algorithm.
It works by repeatedly swapping adjacent elements if they are in the wrong order.
Because the largest element “bubbles up” to the end in each pass, the algorithm is
called Bubble Sort.
if (swapped == 0) return 0;
arr = [5, 1, 4, 2, 8]
break; }
bubble_sort(arr)
}
print("Sorted array:", arr)
}
To be continued…