IT12 – Data Structure & Algorithms
IT12 – Data Structure & Algorithms
Arrays and Lists are fundamental linear data structures used to store collections of data.
Arrays use contiguous memory locations to store data, whereas Lists may use dynamic
memory and flexible sizing depending on the implementation.
2. ARRAYS
2.1 Definition
Arrays are stored in contiguous memory locations. If the base address is 1000 and the size
of int is 4 bytes, then arr[2] would be stored at address 1008 (1000 + 2*4).
One-dimensional Array
Multidimensional Arrays
2.5 Operations on Arrays
2.6 Advantages
Simplicity in implementation
2.7 Disadvantages
Fixed size
3. TWO-DIMENSIONAL ARRAYS
A 2D array is an array of arrays. It's used to store data in the form of a table or matrix.
Declaration in C/C++:
int matrix[3][4];
Applications:
Matrix operations
Image processing
Game development
4. SPARSE MATRICES
A sparse matrix is a matrix that has a large number of zero elements.
Save space
Representations:
Triplet representation
Linked representation
5. STRINGS
Strings are arrays of characters ending with a null character (\0 in C).
Declaration:
String Operations:
Copy
Concatenate
Compare
Length
Reverse
6. APPLICATIONS
Mathematical computations
7. SUMMARY
Arrays are the most basic yet powerful data structures that form the building blocks of many
algorithms and higher-level structures. Mastery over arrays and their variations lays the
groundwork for tackling complex algorithmic challenges.
2. Linked Lists
INTRODUCTION
A linked list is a linear data structure where each element is a separate object, called a node.
Each node contains data and a reference (or link) to the next node in the sequence. Unlike
arrays, linked lists do not require contiguous memory and allow dynamic memory allocation.
Each node points to the next node and the last node points to NULL.
struct Node {
int data;
};
Each node contains two links: one to the next node and another to the previous node.
struct Node {
int data;
};
4. ADVANTAGES
Dynamic size
Efficient insertions/deletions
5. DISADVANTAGES
6. APPLICATIONS
7. SUMMARY
Linked lists provide flexibility in memory usage and ease of insertion/deletion compared to
arrays. Understanding various types of linked lists is essential for building efficient data
structures.
3. Stacks and Queues
INTRODUCTION
Stacks and Queues are linear data structures that follow different principles for element
access. A stack uses the LIFO (Last In, First Out) principle, whereas a queue uses FIFO (First
In, First Out).
2. STACKS
2.1 Definition
2.2 Implementation
Using Arrays
int stack[MAX];
2.3 Operations
2.4 Applications
3.1 Definition
A queue allows elements to be inserted at the rear and removed from the front.
Simple Queue
Circular Queue
Priority Queue
3.3 Implementation
Using Arrays
#define SIZE 5
int queue[SIZE];
3.4 Operations
3.5 Applications
Job Scheduling
Buffer Handling
Resource Management
4. DIFFERENCE BETWEEN STACK AND QUEUE
5. SUMMARY
Stacks and Queues are key linear structures useful in many real-world scenarios like task
scheduling, expression parsing, and memory management. Mastering their operations and
variations prepares students for advanced algorithmic problems.
4. Trees and Heaps
INTRODUCTION
A heap is a special tree-based data structure that satisfies the heap property.
2. TREES
2.1 Terminology
Binary Search Tree (BST): Left child < Root < Right child
Insertion
Deletion
Traversal:
o Level-order (Breadth-first)
2.4 Applications of Trees
Expression trees
File systems
3. HEAPS
3.1 Definition
3.3 Applications
Priority Queues
CPU Scheduling
4. SUMMARY
Trees and Heaps are powerful hierarchical data structures. Trees support efficient search and
hierarchical organization, while heaps are ideal for priority-based operations and sorting.
5. Sorting, Searching, Hashing,
and Heaps
INTRODUCTION
Sorting and Searching are fundamental operations in computer science used to manage and
retrieve data efficiently. Hashing is a technique to map data of arbitrary size to fixed-size
values (hash codes), allowing for constant time average-case lookup.
2. SORTING ALGORITHMS
Selects the smallest/largest element and swaps it with the first unsorted element.
3. SEARCHING ALGORITHMS
Open Addressing:
o Linear Probing
o Quadratic Probing
o Double Hashing
Symbol tables
Caches
Password storage
5. SUMMARY
Sorting helps organize data, searching retrieves data, and hashing allows fast access to data.
Efficient use of these techniques improves algorithm performance significantly.