Looking for AKTU Data Structure Unit 1 Notes KCS 301? Here, you can find complete and easy-to-understand notes for Unit 1 of the AKTU Data Structures subject. These notes are prepared for B.Tech students to help them understand important concepts, prepare for semester examinations, and revise the topics covered in the KCS 301 syllabus.
Unit 1 of Data Structures introduces the basic concepts of data structures, their types, classification, and operations. It also covers important topics such as arrays, pointers, structures, and their applications (as prescribed in the applicable syllabus). The explanations, examples, and practice questions help students build a strong foundation before moving to advanced data structures.
On this page, you will find unit-wise study material, important questions, explanations, and examples to support your AKTU exam preparation. Whether you are preparing for your semester examination or revising important concepts, these AKTU Data Structure Notes will help you study in a simple and organized way.
You can also explore our other units of KCS 301 to complete your Data Structures preparation.
AKTU Data Structure Unit 1 Syllabus (KCS-301)
Introduction to Data Structure: Basic Terminology, Elementary Data Organization, Built in Data Types in C. Algorithm, Efficiency of an Algorithm, Time and Space Complexity
Asymptotic Notations: Big Oh, Big Theta and Big Omega, Time-Space Trade-off. Abstract Data Types (ADT).
Arrays: Definition, Single and Multidimensional Arrays, Representation of Arrays: Row Major Order and Column Major Order, Derivation of Index Formulae for 1-D, 2-D, 3-D and n-D Arrays, Application of Arrays, Sparse Matrices and their Representations.
Linked Lists: Array Implementation and Pointer Implementation of Singly Linked Lists, Doubly Linked List, Circularly Linked List, Operations on a Linked List: Insertion, Deletion, Traversal, Polynomial Representation and Addition, Subtraction & Multiplication of Single Variable & Two Variables Polynomial.
What is a Data Structure?
A data structure is a particular way of organizing, storing, and managing data in a computer so that it can be accessed, modified, processed, and retrieved efficiently.
Data structures help programmers handle large amounts of information systematically. They determine how data elements are arranged in memory and how operations such as insertion, deletion, searching, sorting, and traversal are performed.
Why are Data Structures Required?
Data structures are essential in computer programming for the following reasons:
- Efficient data storage: Organize data in a structured manner.
- Fast data access: Enable efficient retrieval of information.
- Memory optimization: Use available memory effectively.
- Easy data manipulation: Support insertion, deletion, and modification.
- Improved performance: Reduce execution time for operations.
- Handling complex data: Represent hierarchical and interconnected information.
- Reusability: Support reusable algorithms and software components.
Basic Operations on Data Structures
| Operation | Description |
|---|---|
| Traversal | Visiting each element of a data structure |
| Insertion | Adding a new element |
| Deletion | Removing an existing element |
| Searching | Finding a specific element |
| Sorting | Arranging elements in a particular order |
| Merging | Combining two data structures |
| Updating | Modifying an existing element |
Classification of Data Structures

Data structures can be classified into two major categories.
A. Primitive Data Structures
Primitive data structures are the basic data types provided by a programming language. They are used to store single values and form the building blocks of more complex data structures.
Examples of Primitive Data Structures in C:
int: Used to store whole numbers without decimal points, such as10,25, and-5.char: Used to store a single character, such as'A','b', or'5'.float: Used to store decimal numbers with single precision, such as10.5or25.75.double: Used to store decimal numbers with double precision, providing more accuracy thanfloat.void: Represents the absence of a value and is commonly used for functions that do not return anything. It is an incomplete type and is not used to declare an ordinary variable.
A pointer is not a primitive type in C. It is a derived type, and it is listed with arrays and functions under Derived Data Types below.
B. Non-Primitive Data Structures
Non-primitive data structures are created using primitive data types to store, organize, and manage multiple values efficiently.
Non-Primitive Data Structures are further classified into:
1. Linear Data Structures
In linear data structures, elements are arranged sequentially, where each element is connected to its previous and next element (except the first and last elements).
Examples of Linear Data Structures:
- Arrays: A collection of elements of the same data type stored in contiguous memory locations and accessed using an index.
- Linked Lists: A collection of nodes where each node stores data and a pointer to the next node (and sometimes the previous node).
- Stacks: A linear data structure that follows the LIFO (Last In, First Out) principle, where the last inserted element is removed first.
- Queues: A linear data structure that follows the FIFO (First In, First Out) principle, where the first inserted element is removed first.
2. Non-Linear Data Structures
In non-linear data structures, elements are not arranged sequentially. Instead, they are organized in hierarchical or interconnected relationships.
Examples of Non-Linear Data Structures
- Trees: A hierarchical data structure consisting of nodes connected through edges, with a root node at the top.
- Graphs: A non-linear data structure consisting of vertices (nodes) and edges that represent connections between them.
Difference Between Linear and Non-Linear Data Structures
| Linear Data Structures | Non-Linear Data Structures |
|---|---|
| Elements are arranged sequentially | Elements are arranged hierarchically or interconnected |
| Each element generally has a predecessor and successor, except endpoints | An element may have multiple connections |
| Traversal is usually sequential | Traversal may follow multiple paths |
| Examples: Array, Linked List, Stack, Queue | Examples: Tree, Graph |
Data Types in C: Basic, Derived and User-Defined
A data type specifies the type of value a variable can store, the memory requirements, the range of values, and the operations that can be performed on it.
C provides different data types to store various forms of data.
A. Basic Data Types
Basic data types are predefined data types in C that are used to store fundamental values such as integers, characters, and decimal numbers.
| Data Type | Purpose | Example |
|---|---|---|
int | Stores integer values | int age = 20; |
char | Stores a character | char grade = 'A'; |
float | Stores single-precision floating point | float marks = 85.5f; |
double | Stores double-precision floating point | double pi = 3.14159; |
void | Represents absence of a value | void display(void); |
B. Derived Data Types
Derived data types are formed using basic data types.
Examples:
- Arrays: A collection of elements of the same data type stored in contiguous memory locations.
- Pointers: Variables that store the memory addresses of other variables.
- Functions: Blocks of code designed to perform specific tasks and can be called whenever needed.
Derived Data Types Implementation in C
int marks[5];
int *ptr;
int calculate(int a, int b);
C. User-Defined Data Types
User-defined data types allow programmers to create custom data structures.
Examples:
- Structure (
struct): A user-defined data type that groups variables of different data types under a single name. - Union (
union): A user-defined data type in which all members share the same memory location. - Enumeration (
enum): A user-defined data type that assigns names to a set of integer constants. - Typedef (
typedef): A keyword used to create an alternative name (alias) for an existing data type.
struct Implementation in C
struct Student {
int roll;
char name[20];
float marks;
};
Data Type Modifiers
In C programming, data type modifiers are keywords used to modify the size, range, or sign of basic data types. They help programmers store different ranges of values based on the requirements of a program.
Types of Data Type Modifiers in C
short– Specifies a shorter integer type, such asshort int. The C standard sets a minimum range. It does not guarantee that every compiler storesshortin fewer bytes thanint.long– Specifies a longer integer type, such aslong int. A compiler may store it in more bytes thanint, but that size is not the same on every system.signed– Allows a variable to store both positive and negative values.unsigned– Allows a variable to store only non-negative values, providing a larger positive range.
Example
#include <stdio.h>
int main() {
unsigned int count = 100;
long int population = 1000000;
short int age = 25;
signed int temperature = -10;
printf("Count: %u\n", count);
printf("Population: %ld\n", population);
printf("Age: %hd\n", age);
printf("Temperature: %d\n", temperature);
return 0;
}
Checking the Size of Data Types
The size of modified data types may vary depending on the compiler and system architecture. You can use the sizeof() operator to determine the memory occupied by a data type or variable.
#include <stdio.h>
int main() {
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of short int: %zu bytes\n", sizeof(short int));
printf("Size of long int: %zu bytes\n", sizeof(long int));
printf("Size of unsigned int: %zu bytes\n", sizeof(unsigned int));
return 0;
}
What Is an Algorithm?
An algorithm is a finite sequence of well-defined instructions used to solve a particular computational problem.
An algorithm accepts input, processes it through a sequence of operations, and produces the required output.
Characteristics of an Algorithm
An algorithm must satisfy the following properties:
- Input: An algorithm accepts zero or more input values to perform a task.
- Output: It must produce at least one output or result.
- Definiteness: Every instruction must be clear, precise, and unambiguous.
- Finiteness: An algorithm must terminate after a finite number of steps.
- Effectiveness: Every instruction in an algorithm must be sufficiently basic, precise, and executable in a finite amount of time using available resources.
- Correctness: It must produce the expected result for all valid inputs.
Example: Algorithm to Find the Largest of Two Numbers
Consider a problem where we need to find the largest number between two given numbers, A and B.
Algorithm:
Start.
Read two numbers A and B.
Compare A and B.
If A is greater than B, display A.
Otherwise, display B.
Stop.
Example Input:
A = 20
B = 15
Output:
20 is the largest number.
The algorithm compares both numbers and displays the greater value.
What is a Flowchart?
A flowchart is a graphical representation of an algorithm that uses standard symbols to illustrate the sequence of steps involved in solving a problem.
It makes the program logic easier to understand, analyze, and communicate before writing the actual code.

Common Flowchart Symbols
Flowchart symbols are standard graphical representations used to describe different steps and operations in an algorithm or process.
| Symbol | Name | Purpose |
|---|---|---|
| Oval | Terminal | Represents the Start or End of a flowchart. |
| Rectangle | Process | Represents calculations or processing operations. |
| Parallelogram | Input/Output | Represents data input or output operations. |
| Diamond | Decision | Represents a condition with Yes/No or True/False branches. |
| Arrow | Flow Line | Indicates the direction of program execution. |
Algorithm Efficiency
Algorithm efficiency refers to the amount of computational resources required by an algorithm to solve a problem.
The two primary resources used to measure efficiency are:
- Time: The number of computational steps performed.
- Space: The amount of memory required.
An efficient algorithm produces correct results while minimizing resource consumption.
Factors Affecting Algorithm Efficiency
The efficiency of an algorithm depends on several factors:
- Input Size: Larger input data may require more processing time and memory.
- Algorithm Design: A well-designed algorithm generally performs fewer unnecessary operations.
- Data Structure Selection: Choosing suitable data structures, such as arrays, linked lists, stacks, or hash tables, can improve performance.
- Hardware Architecture: Processor speed, RAM, and system architecture can affect execution performance.
- Programming Language and Compiler: Language features, compiler optimizations, and runtime environments can influence execution speed.
- Number of Operations: The number of comparisons, calculations, and iterations affects execution time.
- Memory Requirements: The amount of memory used by an algorithm affects its space efficiency.
Best Case, Average Case, and Worst Case
An algorithm can perform differently depending on the input data it receives. To understand its performance, we analyze it under three conditions: Best Case, Average Case, and Worst Case.
Best Case: Represents the minimum number of operations an algorithm performs for a given input size. It occurs when the input is in the most favorable condition.
Average Case: The expected number of operations over all possible inputs of a particular size, assuming a specified input distribution.
Worst Case: Represents the maximum number of operations an algorithm performs for a given input size. It occurs when the input is in the least favorable condition.
Example of Best Case, Average Case, and Worst Case
1. Best Case Example
Consider an array:
[10, 20, 30, 40, 50]
Suppose we are searching for the element 10.
- The element
10is present at the first position. - Linear Search checks the first element and finds the target immediately.
- Only 1 comparison is required.
Time Complexity: O(1)
2. Average Case Example
Finding one middle element in a single array is not the average case. Average case is the expected number of comparisons when the key is equally likely to be at any position.
For a successful Linear Search in an array of n distinct elements, one comparison is needed at the first position, two at the second, and n at the last. If each position is equally likely, the average number of comparisons is:
(1 + 2 + 3 + ... + n) / n = (n + 1) / 2
That quantity grows in proportion to n, so the average-case time complexity is O(n). This assumes the key is present.
3. Worst Case Example
Consider an array:
[10, 20, 30, 40, 50]
Suppose we are searching for the element 50.
- Linear Search checks
10,20,30, and40. - Finally, it checks
50and finds the element. - A total of 5 comparisons are required.
Time Complexity: O(n)
Iterative vs Recursive Algorithms
Iterative Algorithm
An Iterative Algorithm is an algorithm that repeats a set of instructions using loops such as for, while, or do-while until a specified condition is satisfied.
In simple words, an iterative algorithm performs the same task repeatedly using a loop.
Example of iterative sum:
int sum(int n) {
int s = 0;
for (int i = 1; i <= n; i++)
s += i;
return s;
}
Recursive Algorithm
A Recursive Algorithm is an algorithm that solves a problem by calling itself with smaller inputs until a stopping condition is reached.
In simple words, recursion means a function calls itself repeatedly to solve a smaller version of the same problem.
Every recursive algorithm has two important parts:
- Base Case: The condition that stops the recursion.
- Recursive Case: The part where the function calls itself with a smaller input.
Example of recursive sum:
This recursive function assumes that n is a non-negative integer. The base case is reached when n becomes 0.
int sum(int n) {
if (n == 0)
return 0;
return n + sum(n - 1);
}
| Iterative | Recursive |
|---|---|
| Uses loops | Uses function calls |
| Usually uses less auxiliary memory | Uses call-stack memory |
| Avoids recursion overhead | Has recursion overhead |
| Suitable for repetitive operations | Suitable for divide-and-conquer and recursive structures |
What is Time Complexity?
Time Complexity is a measure of how much time an algorithm takes to complete its execution as the input size increases.
It does not necessarily measure actual execution time in seconds. Instead, it describes how the computational work grows as input size increases.
Time complexity is generally represented using asymptotic notation.

Common Time Complexities
Time Complexity is a measure of the amount of time an algorithm takes to execute as the input size increases. It is generally represented using Big-O notation.
| Complexity | Name | Example |
|---|---|---|
| O(1) | Constant | Accessing an array element |
| O(log n) | Logarithmic | Binary Search |
| O(n) | Linear | Linear Search |
| O(n log n) | Linearithmic | Merge Sort |
| O(n²) | Quadratic | Bubble Sort |
| O(n³) | Cubic | Three nested loops |
| O(2ⁿ) | Exponential | Basic recursive subset generation |
| O(n!) | Factorial | Brute-force permutations |
Examples of Time Complexity
Example 1: Constant Complexity
int x = arr[0];
Only one element is accessed.
Time complexity: O(1).
Example 2: Linear Complexity
for (int i = 0; i < n; i++) {
printf("%d", i);
}
The loop executes n times.
Time complexity: O(n).
Example 3: Quadratic Complexity
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
printf("%d %d", i, j);
}
}
The outer loop executes n times and the inner loop executes n times.
Total operations:
Time complexity: O(n²).
Example 4: Logarithmic Complexity
while (n > 1) {
n = n / 2;
}
Each iteration reduces the input size by half.
Time complexity: O(log n).
What is Space Complexity?
Space Complexity is the amount of memory required by an algorithm to execute and produce the desired output. It measures how much memory an algorithm needs as the size of the input increases.
Space complexity is an important factor in algorithm analysis because it helps determine how efficiently an algorithm uses computer memory.
It includes memory required for variables, data structures, function calls, recursion, and other temporary storage during program execution.
It includes:
- Input Space: Memory required to store the input data provided to an algorithm.
- Auxiliary Space: Extra memory used by an algorithm during execution, excluding input storage.
- Variables: Memory allocated to store values used during program execution.
- Data Structures: Memory used by arrays, linked lists, stacks, queues, trees, and other structures.
- Recursion Stack: Memory required to maintain function calls during recursive execution.
- Temporary Storage: Additional memory used to store intermediate results during processing.
Auxiliary Space
Auxiliary Space is the extra memory or temporary storage used by an algorithm during its execution, excluding the memory required to store the input data.
It includes memory used for temporary variables, additional arrays, data structures, and recursion stack space.
Auxiliary space is an important concept in algorithm analysis because it helps measure how efficiently an algorithm uses additional memory.
Example:
int sum(int arr[], int n) {
int total = 0;
for (int i = 0; i < n; i++)
total += arr[i];
return total;
}
The algorithm uses only a constant number of extra variables.
Auxiliary space complexity: O(1).
Examples of Space Complexity
1. Space Complexity of an Array
int arr[n];
The array requires memory proportional to n.
Space complexity: O(n).
2.Space Complexity of Recursive Algorithms
int factorial(int n) {
if (n == 0)
return 1;
return n * factorial(n - 1);
}
The recursion depth is n.
Auxiliary space complexity: O(n).
Asymptotic Notations
Asymptotic notations are mathematical tools used to describe the growth rate of an algorithm’s time or space requirements as the input size approaches infinity.
They help compare algorithms independently of hardware, programming languages, and implementation details.
The three main asymptotic notations are:
- Big O — Upper bound.
- Big Omega — Lower bound.
- Big Theta — Tight bound.
Big O Notation — O
Big O notation represents an asymptotic upper bound on the growth of a function.
It is commonly used to express worst-case complexity.
Mathematical definition:
Big Omega Notation — Ω
Big Omega notation represents an asymptotic lower bound on the growth of a function.
Big Theta Notation — Θ
Big Theta notation represents a tight asymptotic bound.
It describes functions that grow at the same order of magnitude.
Comparison of Asymptotic Notations
| Notation | Meaning | Interpretation |
|---|---|---|
| O(g(n)) | Upper bound | Growth does not exceed a constant multiple of g(n) eventually |
| Ω(g(n)) | Lower bound | Growth is at least a constant multiple of g(n) eventually |
| Θ(g(n)) | Tight bound | Growth is bounded both above and below by constant multiples |
What is Time-Space Trade-Off?
Time-Space Trade-Off is a concept in algorithm design where we balance the execution time of a program and the memory (space) it uses.
Time-Space Trade-Off means using more memory to make a program run faster or using less memory while allowing the program to take more time.
It helps programmers decide whether to prioritize execution speed or memory usage.
Types of Time-Space Trade-Off
1. More Space, Less Time
A program uses additional memory to store precomputed results or lookup tables so that information can be accessed quickly whenever required. Instead of calculating the same result repeatedly, the program stores the result in memory and reuses it when needed.
Examples:
- Hash tables.
- Memoization.
- Lookup tables.
- Caching.
2. Less Space, More Time
A program uses less memory by avoiding the storage of extra data or previously calculated results. Instead, it calculates the required values whenever they are needed. As a result, the program may perform the same calculations repeatedly, which can increase execution time.
Examples:
- In-place sorting.
- Repeated calculations instead of storing results.
- Space-efficient algorithms.
Abstract Data Types (ADT)
An Abstract Data Type (ADT) is a logical description of a data structure that specifies the data it stores and the operations that can be performed on it, without specifying the internal implementation.
An ADT defines what operations are performed, while the data structure defines how those operations are implemented.
Components of an ADT
An ADT consists of:
- Data Objects: The collection of data elements stored in the ADT.
- Data Relationships: The logical relationships between the data elements.
- Operations: The functions or actions that can be performed on the data.
- Rules Governing Operations: The conditions and restrictions that define how operations are performed.
Examples of ADTs
1. Stack ADT
A stack follows the Last In, First Out (LIFO) principle.
Operations of Stack ADT
push()— Insert an element.pop()— Remove the top element.peek()— Access the top element.isEmpty()— Check whether the stack is empty.
2. Queue ADT
A queue follows the First In, First Out (FIFO) principle.
Operations of Queue ADT
enqueue()— Insert an element.dequeue()— Remove an element.front()— Access the first element.isEmpty()— Check whether the queue is empty.
3. List ADT
A list is an ordered collection of elements.
Operations of List ADT
- Insert.
- Delete.
- Search.
- Retrieve.
- Traverse.
What is Arrays?
An array is a linear data structure that stores a collection of elements of the same data type in contiguous memory locations.
Each element can be accessed using an index.
In C, array indexing begins at 0.
Example of Arrays
int arr[5] = {10, 20, 30, 40, 50};

Characteristics of Arrays
- Stores homogeneous elements.
- Uses contiguous memory locations.
- Supports direct access using indices.
- Has a fixed size in standard fixed-size array declarations.
- Supports efficient traversal.
- Insertion and deletion in the middle generally require shifting elements.
Advantages of Arrays
- Direct access to elements.
- Simple implementation.
- Efficient memory access due to contiguous storage.
- Suitable for storing homogeneous data.
- Easy traversal and processing.
Disadvantages of Arrays
- Fixed capacity for ordinary fixed-size arrays.
- Insertion and deletion can be expensive.
- May cause memory wastage if allocated capacity is underused.
- Requires contiguous memory.
- Cannot naturally grow or shrink without creating a new array.
Types of Arrays in Data Structures
One-Dimensional Array
A One-Dimensional Array is a linear data structure that stores a collection of elements of the same data type in contiguous memory locations. Each element is accessed using a single index.
In C programming, array indexing starts from 0, and the last element is accessed using the index n-1, where n is the total number of elements.

Declaration:
int arr[5];
Initialization:
int arr[5] = {10, 20, 30, 40, 50};
Accessing an element:
printf("%d", arr[2]);
Output:
30
Two-Dimensional Array
A Two-Dimensional Array is a linear data structure that stores elements of the same data type in the form of rows and columns. It is also called a matrix because data is arranged in a tabular format.
Each element is accessed using two indices: one for the row and another for the column.
In C programming, the indexing of rows and columns starts from 0.
Declaration:
int matrix[3][3];

Initialization:
int matrix[2][3] = {
{1, 2, 3},
{4, 5, 6}
};
Accessing an element
printf("%d", matrix[1][2]);
Output:
6
Multidimensional Arrays
A Multidimensional Array is an array containing two or more dimensions. It is used to store elements of the same data type in multiple dimensions, such as rows, columns, and additional levels.
Multidimensional arrays are useful for representing complex data such as matrices, tables, 3D objects, and scientific data.
In C programming, multidimensional arrays are commonly implemented using two or more pairs of square brackets.
Example:
int arr[2][3][4];
This is a three-dimensional array.
It contains:
elements.
Multidimensional arrays are useful in:
- Matrix operations.
- Image processing.
- Scientific computing.
- 3D graphics.
- Tensor-based computation.
What Are the Different Operations Performed on Arrays?
1. Array Traversal
Array Traversal is the process of visiting and accessing every element of an array exactly once to perform operations such as displaying, searching, updating, or processing data.
Traversal is generally performed using loops such as for and while loops.
Algorithm of Array Traversal:
TRAVERSE(A, n)
1. FOR i = 0 TO n-1
2. PRINT A[i]
3. END FOR
C program:
void traverse(int arr[], int n) {
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
}
Time complexity: O(n).
2. Insertion in an Array
Insertion in an Array is the process of adding a new element at a specified position in an existing array. During insertion, the elements at and after the selected position may need to be shifted one position to the right to create space for the new element.
Insertion is one of the basic operations performed on arrays in data structures.
In an array, insertion can be performed at the beginning, at the end, or at a specific position.
Suppose:
A = [10, 20, 30, 40]
Insert 25 at index 2.
Result:
[10, 20, 25, 30, 40]
Algorithm of Insertion in an Array:
INSERT(A, n, pos, item)
1. FOR i = n-1 DOWNTO pos
2. A[i+1] = A[i]
3. END FOR
4. A[pos] = item
5. n = n + 1
C program
void insert(int arr[], int *n, int pos, int item) {
for (int i = *n - 1; i >= pos; i--) {
arr[i + 1] = arr[i];
}
arr[pos] = item;
(*n)++;
}
This function assumes the array still has unused capacity and that pos is from 0 up to the current number of elements. Here n is how many elements are stored, not the allocated size. If the array is already full, or pos is outside that range, the function writes past the array.
Time complexity:
- Best case: O(1), insertion at the end when capacity is available.
- Worst case: O(n), insertion at the beginning.
3. Deletion in an Array
Deletion in an Array is the process of removing an existing element from a specified position in an array. After deleting an element, the remaining elements are shifted one position to the left to fill the empty space.
Deletion is one of the basic operations performed on arrays in data structures.
In an array, deletion can be performed at the beginning, at the end, or at a specific position.
Example:
[10, 20, 30, 40, 50]
Delete the element at index 2.
Result:
[10, 20, 40, 50]
Algorithm of Deletion in an Array:
DELETE(A, n, pos)
1. FOR i = pos TO n-2
2. A[i] = A[i+1]
3. END FOR
4. n = n - 1
C program:
void deleteElement(int arr[], int *n, int pos) {
for (int i = pos; i < *n - 1; i++) {
arr[i] = arr[i + 1];
}
(*n)--;
}
This function assumes the array is not empty and that pos is a valid index from 0 to n - 1. It does not check those conditions before shifting the elements.
Time complexity:
- Best case: O(1), deleting the last element.
- Worst case: O(n), deleting the first element.
4. Searching in an Array
Searching is the process of locating a particular element in an array.
1. Linear Search
Linear Search is a searching technique that examines each element of an array sequentially until the required element (key) is found or the array ends.
It can be applied to both sorted and unsorted arrays.
int linearSearch(int arr[], int n, int key) {
for (int i = 0; i < n; i++) {
if (arr[i] == key) {
return i;
}
}
return -1;
}
The function returns the index of the key. It returns -1 when the key is not in the array.
Time complexity:
Time Complexity:
- Best Case: O(1) – Element is found at the first position.
- Average Case: O(n) – Several elements are checked before finding the key.
- Worst Case: O(n) – Element is at the last position or not present.
Space Complexity: O(1).
2. Binary Search
Binary Search is an efficient searching technique that repeatedly divides a sorted array into two halves to find the required element.
It works only on sorted arrays.
int binarySearch(int arr[], int n, int key) {
int low = 0;
int high = n - 1;
while (low <= high) {
int mid = low + (high - low) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] < key)
low = mid + 1;
else
high = mid - 1;
}
return -1;
}
Time Complexity:
- Best Case: O(1) – Element is found at the middle position in the first comparison.
- Average Case: O(log n).
- Worst Case: O(log n) – The search space is repeatedly divided into halves.
Space Complexity: O(1) for the iterative implementation.
Representation of Arrays
An array is a linear data structure that stores elements of the same data type in contiguous memory locations. Each element is accessed using an index or subscript.
Since arrays are stored in continuous memory locations, the computer uses mathematical formulas to calculate the memory address of each element.
Arrays can be represented in memory using two major techniques:
- Row Major Order
- Column Major Order
Representation of Arrays in Memory
Array representation in memory refers to the way array elements are stored in the computer’s memory.
Each array element occupies a fixed amount of memory, called the size of an element.
Row Major Order
Row Major Order is a method of storing a multidimensional array in memory where all elements of the first row are stored first, followed by the elements of the second row, and so on.
In this method, elements are stored row by row.
Example of row major order:
Consider a 2D array:
Two-dimensional array
1 2 3
4 5 6
7 8 9
Elements arranged in 3 rows and 3 columns
Memory storage in Row Major Order
1 2 3 4 5 6 7 8 9
Storage sequence: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → 9
Here, the first row (1, 2, 3) is stored first, followed by the second row (4, 5, 6), and then the third row (7, 8, 9).
Row Major Order Formula for a 2D Array
For a 2D array A[m][n], the address of an element is calculated using:
Where:
- BA = Base address.
- i,j = Row and column indices.
- L1,L2 = Lower bounds of row and column.
- N = Number of columns.
- w = Size of each element.
Example
Consider an array A[3][3].
Given:
- Base address = 1000
- Element size = 4 bytes
- Required element = A[2][1]
- Lower bounds = 0, 0
- Number of columns = 3
Using the formula:
Therefore, the memory address of A[2][1] is 1028.
Column Major Order
Column Major Order is a method of storing a multidimensional array in memory where all elements of the first column are stored first, followed by the elements of the second column, and so on.
In this method, elements are stored column by column.
Example of Column Major Order
Consider the following 2D array:
Two-dimensional array
1 2 3
4 5 6
7 8 9
Memory storage in Column Major Order
1 4 7 2 5 8 3 6 9
Storage sequence: 1 → 4 → 7 → 2 → 5 → 8 → 3 → 6 → 9
Here, the first column (1, 4, 7) is stored first, followed by the second column (2, 5, 8), and then the third column (3, 6, 9).
Column Major Order Formula for a 2D Array
For a 2D array A[m][n], the address of an element is calculated using:
Where:
- BA = Base address.
- i,j = Row and column indices.
- L1,L2 = Lower bounds.
- M = Number of rows.
- w = Size of each element.
Example
Consider an array A[3][3].
Given:
- Base address = 1000
- Element size = 4 bytes
- Required element = A[2][1]
- Lower bounds = 0, 0
- Number of rows = 3
Using the formula:
Therefore, the memory address of A[2][1] is 1020.
Derivation of Index Formulae for 1D Array
A one-dimensional array contains elements arranged in a single sequence.
Example:
A[5]={10,20,30,40,50}
To calculate the address of any element, we use the following formula.
Derivation
Let:
- BA = Base address.
- LB = Lower bound.
- i = Required index.
- w = Size of each element.
The first element is stored at the base address.
The number of elements before the required element is:
Each element occupies w bytes.
Therefore, the offset is:
Adding this offset to the base address:
Example of Index Formulae for 1D Array
Find the address of A[4].
Given:
- Base address = 1000
- Lower bound = 0
- Element size = 4 bytes
Derivation of Index Formulae for 2D Array
A two-dimensional array contains elements arranged in rows and columns.
Example:
A[3][4]
It contains 3 rows and 4 columns.
A. Row Major Order Derivation
In row major order, all elements of each row are stored continuously.
For an array A[m][n]:
- Number of columns = n.
- Number of complete rows before row i = i-L1.
- Number of elements in each complete row = n.
- Number of elements before column j in the current row = j-L2.
Total elements before A[i][j]:
Multiplying by element size and adding the base address:
B. Column Major Order Derivation
In column major order, all elements of each column are stored continuously.
For an array A[m][n]:
- Number of rows = m.
- Number of complete columns before column j = j-L2.
- Number of elements in each complete column = m.
- Number of elements before row i in the current column = i-L1.
Total elements before A[i][j]:
Therefore:
Derivation of Index Formulae for 3D Array
A three-dimensional array contains elements arranged in three dimensions: rows, columns, and depth.
Example:
A[2][3][4]
Here:
- Number of rows = 2.
- Number of columns = 3.
- Number of depth elements = 4.
A. Row Major Order Derivation
In 3D row major order, the last dimension changes fastest.
For an array A[m][n][p], the number of elements before A[i][j][k] is calculated as follows:
1. Complete planes before the required plane:
2. Complete rows before the required row:
3. Elements before the required column:
Adding all three:
B. Column Major Order Derivation
In 3D column major order, the first dimension changes fastest.
The number of elements before A[i][j][k] is:
1. Complete blocks before the required depth:
2. Complete columns before the required column:
3. Elements before the required row:
Therefore:
Derivation of Index Formulae for nD Array
An n-dimensional array is an array that contains more than three dimensions.
It is used to represent complex data with multiple indices.
For example:
Where d1,d2,…,dn represent the sizes of each dimension.
A. Row Major Order Formula
In row major order, the last dimension changes fastest.
The address formula for an n-dimensional array is:
For the last dimension, the empty product is considered 1.
B. Column Major Order Formula
In column major order, the first dimension changes fastest.
The address formula is:
Applications of Arrays
Arrays are widely used in programming because they allow efficient storage and access of multiple values using a single variable name.
1. Storing and Processing Data
Arrays are used to store multiple values of the same data type, such as student marks, employee salaries, and product prices.
2. Matrix Operations
Two-dimensional arrays are used to represent matrices and perform operations such as matrix addition, subtraction, and multiplication.
3. Searching and Sorting
Arrays are used to implement searching and sorting algorithms such as:
- Linear Search
- Binary Search
- Bubble Sort
- Selection Sort
- Insertion Sort
- Quick Sort
4. Implementing Stack and Queue
Arrays are used to implement linear data structures such as stacks and queues.
- Stack follows LIFO (Last In, First Out).
- Queue follows FIFO (First In, First Out).
5. Image Processing
Two-dimensional and three-dimensional arrays are used to store pixel values of digital images.
For example, a grayscale image can be represented using a 2D array.
What Is a Sparse Matrix?
A sparse matrix is a matrix in which most of the elements are zero. A matrix is considered sparse when the number of zero elements is significantly greater than the number of non-zero elements.
Sparse matrices are commonly used in scientific computing, graph algorithms, machine learning, and engineering applications. Storing all the zero elements requires unnecessary memory, so special storage techniques are used to store only the non-zero elements.
A matrix is considered sparse when the number of zero elements is significantly greater than the number of non-zero elements.
Example:
Why Sparse Matrix Representation is Required?
Storing all elements in a conventional two-dimensional array wastes memory when most elements are zero.
Sparse representation stores only the non-zero elements and their positions.
Benefits of Sparse Matrix
- Reduced memory usage.
- Efficient processing.
- Faster operations in many sparse algorithms.
- Suitable for large matrices with few non-zero elements.
Linked Lists: Definition and Types
A linked list is a linear data structure consisting of a collection of nodes, where each node contains data and one or more links (pointers) that connect it to other nodes.
Unlike arrays, linked list nodes are not required to occupy contiguous memory locations.
A linked list dynamically grows or shrinks through insertion and deletion operations, subject to available memory.
Structure of a Node
A node generally consists of two parts:
- Data field — stores the value.
- Link field — stores the address of another node
Characteristics of Linked Lists
- Dynamic memory allocation.
- Non-contiguous memory storage.
- Sequential access.
- Efficient insertion and deletion when the relevant node or link is known.
- Additional memory required for pointers.
- No direct random access using indices.
Array Implementation and Pointer Implementation of Linked Lists
Array Implementation
In array implementation, linked list nodes are represented using arrays instead of pointers. Two separate arrays are maintained to store node information and the link to the next node.
Two arrays may be maintained:
INFO[]— Stores the data or information of each node.LINK[]— Stores the index of the next node.
A variable called START stores the index of the first node in the linked list. If the list is empty, START is set to -1.
Pointer Implementation
In pointer implementation, each linked list node is dynamically allocated in memory and contains two parts: data and a pointer to the next node.
A node consists of:
- Data: Stores the actual value.
- Next Pointer: Stores the address of the next node.
A pointer called START or HEAD stores the address of the first node. If the linked list is empty, it is set to NULL.
Example:
struct Node {
int data;
struct Node *next;
};
Singly Linked List
A singly linked list is a linear data structure in which each node contains two parts: data and a pointer to the next node. Each node is connected to the next node using a pointer, forming a sequence of elements.
The last node contains a NULL pointer, indicating the end of the linked list.
Structure of a Node
A node in a singly linked list consists of:
Next Pointer: Stores the address of the next node.
Data: Stores the actual value or information.

Creation of a Singly Linked List
A linked list can be created by dynamically allocating nodes and linking them together.
#include
#include
struct Node {
int data;
struct Node *next;
};
int main() {
struct Node *head = NULL;
struct Node *first =
malloc(sizeof(struct Node));
struct Node *second =
malloc(sizeof(struct Node));
if (first == NULL || second == NULL) {
free(first);
free(second);
return 1;
}
first->data = 10;
first->next = second;
second->data = 20;
second->next = NULL;
head = first;
return 0;
}
The created list is:
HEAD → 10 → 20 → NULL
malloc() returns NULL when memory cannot be allocated. Check that pointer before using the node. When the list is no longer needed, release each node with free(), or the program leaks that memory.
Operations on Singly Linked Lists
Traversal in single Singly Linked Lists:
Traversal is the process of visiting each node from the first node to the last node.
Algorithm of Singly Linked Lists:
TRAVERSE(START)
1. PTR = START
2. WHILE PTR != NULL
3. PRINT PTR->DATA
4. PTR = PTR->NEXT
5. END WHILE
void traverse(struct Node *head) {
struct Node *temp = head;
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
}
Time complexity: O(n).
Insertion at the Beginning in Singly Linked List
Insertion at the beginning adds a new node before the current first node.
Algorithm of Insertion at the Beginning in Singly Linked List :
INSERT_BEGIN(START, ITEM)
1. Create NEW node
2. NEW->DATA = ITEM
3. NEW->NEXT = START
4. START = NEW
5. RETURN START
struct Node *insertBegin(struct Node *head, int item) {
struct Node *newNode =
malloc(sizeof(struct Node));
newNode->data = item;
newNode->next = head;
return newNode;
}
Time complexity: O(1).
Insertion at the End in Singly Linked List
Insertion at the end adds a node after the last node.
Algorithm of Insertion at the End in Singly Linked List:
struct Node *insertEnd(struct Node *head, int item) {
struct Node *newNode =
malloc(sizeof(struct Node));
newNode->data = item;
newNode->next = NULL;
if (head == NULL)
return newNode;
struct Node *temp = head;
while (temp->next != NULL)
temp = temp->next;
temp->next = newNode;
return head;
}
Time complexity:
- O(n) without a tail pointer.
- O(1) if a tail pointer is maintained.
Insertion After a Given Node in Singly Linked List
A new node is inserted after a specified node.
Example:
10 → 20 → 40
Insert 30 after 20.
Result:
10 → 20 → 30 → 40
Algorithm of Insertion After a Given Node in Singly Linked List:
INSERT_AFTER(PTR, ITEM)
1. IF PTR = NULL
RETURN
2. Create NEW node
3. NEW->DATA = ITEM
4. NEW->NEXT = PTR->NEXT
5. PTR->NEXT = NEW
void insertAfter(struct Node *ptr, int item) {
if (ptr == NULL)
return;
struct Node *newNode =
malloc(sizeof(struct Node));
newNode->data = item;
newNode->next = ptr->next;
ptr->next = newNode;
}
Time complexity: O(1), when the specified node is already available.
Deletion at the Beginning in Singly Linked List
Deletion at the beginning removes the first node.
Algorithm Deletion at the Beginning in Singly Linked List:
DELETE_BEGIN(START)
1. IF START = NULL
PRINT UNDERFLOW
RETURN
2. TEMP = START
3. START = START->NEXT
4. FREE TEMP
5. RETURN START
struct Node *deleteBegin(struct Node *head) {
if (head == NULL)
return NULL;
struct Node *temp = head;
head = head->next;
free(temp);
return head;
}
Time complexity: O(1).
Deletion at the End in Singly Linked List
Deletion at the end removes the last node.
Algorithm of Deletion at the End in Singly Linked List:
DELETE_END(START)
1. IF START = NULL
RETURN
2. IF START->NEXT = NULL
FREE START
START = NULL
RETURN
3. PTR = START
4. WHILE PTR->NEXT->NEXT != NULL
PTR = PTR->NEXT
5. TEMP = PTR->NEXT
6. PTR->NEXT = NULL
7. FREE TEMP
struct Node *deleteEnd(struct Node *head) {
if (head == NULL)
return NULL;
if (head->next == NULL) {
free(head);
return NULL;
}
struct Node *temp = head;
while (temp->next->next != NULL)
temp = temp->next;
free(temp->next);
temp->next = NULL;
return head;
}
Time complexity: O(n).
Deletion of a Specific Node in Singly Linked List
A node containing a specified value is removed from the list.
Example:
10 → 20 → 30 → 40
Delete 30.
Result:
10 → 20 → 40
struct Node *deleteValue(struct Node *head, int key) {
if (head == NULL)
return NULL;
if (head->data == key) {
struct Node *temp = head;
head = head->next;
free(temp);
return head;
}
struct Node *temp = head;
while (temp->next != NULL &&
temp->next->data != key) {
temp = temp->next;
}
if (temp->next != NULL) {
struct Node *del = temp->next;
temp->next = del->next;
free(del);
}
return head;
}
Time complexity: O(n).
Doubly Linked List
A doubly linked list is a linear data structure in which each node contains three fields: data, a pointer to the previous node, and a pointer to the next node.
It allows traversal in both forward and backward directions, unlike a singly linked list.
Structure of a Node
Each node in a doubly linked list consists of three parts:
- Next Pointer (
next): Stores the address of the next node. It supports traversal in forward directions. - Previous Pointer (
prev): Stores the address of the previous node. It supports traversal in backward directions. - Data: Stores the actual value or information.

Structure of a Doubly Linked List Node
struct Node {
int data;
struct Node *prev;
struct Node *next;
};
Insertion in a Doubly Linked List
Insertion in a doubly linked list means adding a new node at a specific position while maintaining both the previous and next links.
A new node can be inserted:
- At the beginning of the list.
- At the end of the list.
- Before a given node.
- After a given node.
void insertAfter(struct Node *ptr, int item) {
if (ptr == NULL)
return;
struct Node *newNode =
malloc(sizeof(struct Node));
newNode->data = item;
newNode->next = ptr->next;
newNode->prev = ptr;
if (ptr->next != NULL)
ptr->next->prev = newNode;
ptr->next = newNode;
}
The insertion requires updating both previous and next pointers.
Deletion in a Doubly Linked List
Deletion in a doubly linked list means removing an existing node and updating the links of its neighboring nodes.
A node can be deleted:
- From the beginning of the list.
- From the end of the list.
- From a specific position.
- By identifying a particular node.
void deleteNode(struct Node **head,
struct Node **tail,
struct Node *ptr) {
if (ptr == NULL)
return;
if (ptr->prev != NULL)
ptr->prev->next = ptr->next;
else
*head = ptr->next;
if (ptr->next != NULL)
ptr->next->prev = ptr->prev;
else
*tail = ptr->prev;
free(ptr);
}
The head and tail references must also be updated when deleting the first or last node.
Time complexity: O(1) when the node is already identified and the necessary references are available.
Circular Linked List
A circular linked list is a linear data structure in which the last node points back to the first node instead of pointing to NULL. This creates a circular structure in which nodes are connected continuously.
Unlike a singly linked list, a circular linked list does not have a NULL pointer at the end.
Structure of a Circular Linked List
Each node in a circular linked list contains two parts:
- Data: Stores the actual value or information.
- Next Pointer: Stores the address of the next node.

Types of Circular Linked Lists
1. Circular Singly Linked List
A Circular Singly Linked List is a type of linked list in which each node contains two parts: data and a pointer to the next node.
The next pointer of the last node points back to the first node instead of pointing to NULL.
2. Circular Doubly Linked List
A Circular Doubly Linked List is a type of linked list in which each node contains three parts: a previous pointer, data, and a next pointer.
The next pointer of the last node points to the first node, and the previous pointer of the first node points to the last node.
Traversal of a Circular Linked List
Traversal of a Circular Linked List is the process of visiting and accessing each node of the linked list one by one, starting from the first node and continuing until we reach the starting node again.
Unlike a linear linked list, a circular linked list does not end with a NULL pointer. Instead, its last node points back to the first node.
Algorithm of Circular Linked List:
TRAVERSE_CIRCULAR(START)
1. IF START = NULL
RETURN
2. PTR = START
3. REPEAT
PRINT PTR->DATA
PTR = PTR->NEXT
UNTIL PTR = START
C implementation:
void traverseCircular(struct Node *head) {
if (head == NULL)
return;
struct Node *temp = head;
do {
printf("%d ", temp->data);
temp = temp->next;
} while (temp != head);
}
Time complexity: O(n).
Comparison of Singly, Doubly and Circular Linked Lists
| Feature | Singly Linked List | Doubly Linked List | Circular Linked List |
|---|---|---|---|
| Pointers per node | 1 | 2 | Usually 1 or 2 |
| Traversal | Forward | Forward and backward | Circular traversal |
| Last node link | NULL | NULL | Points to first node |
| Memory usage | Lower | Higher | Depends on type |
| Deletion of known node | May require previous node | Efficient | Depends on implementation |
| Complexity | Simple | Moderate | Moderate |
| Applications | Stacks, basic lists | Browser history | Round-robin scheduling |
Polynomial Representation Using Linked Lists
Polynomial Representation
A polynomial is a mathematical expression consisting of variables, coefficients, and non-negative integer exponents.
A single-variable polynomial can be represented as:
Where:
- ai represents the coefficient.
- x represents the variable.
- i represents the exponent.
- n represents the highest degree of the polynomial.
Single-Variable Polynomial Representation
Node Structure
Each node contains three fields:
- Coefficient: Stores the numerical coefficient of the term.
- Exponent: Stores the power of the variable.
- Next Pointer: Stores the address of the next node.
struct PolyNode {
int coeff;
int exp;
struct PolyNode *next;
};
Polynomial Addition Using Linked Lists
Polynomial addition is the process of adding two polynomials by combining terms with the same exponent.
Consider:
Addition:
Polynomial Subtraction Using Linked Lists
Polynomial subtraction is performed by subtracting the coefficients of terms having equal exponents.
Consider:
Then:
Algorithm
The subtraction algorithm is similar to polynomial addition.
- If exponents are equal, subtract coefficients.
- If the first exponent is greater, copy the first term.
- If the second exponent is greater, insert the negative of the second term.
- Copy the remaining terms.
- Remove terms with zero coefficients.
Polynomial Multiplication Using Linked Lists
Polynomial multiplication is performed by multiplying each term of the first polynomial with every term of the second polynomial.
The multiplication rules are:
Therefore:
- Multiply the coefficients.
- Add the exponents.
- Combine terms having equal exponents.
Addition of Two-Variable Polynomials
Two terms can be combined only when both exponents match.
Example:
Addition:
Important Data Structure AKTU Examination Questions – Unit 1
- Explain the representation of two-variable polynomials using linked lists.
- Define data structures. Explain their classification with suitable diagrams.
- Explain the characteristics of a good algorithm. Discuss algorithm efficiency.
- Explain Big O, Omega and Theta notations with mathematical definitions and examples.
- Explain time complexity and space complexity with suitable examples.
- Explain the time-space trade-off in algorithm design.
- Explain Abstract Data Types with examples.
- Explain one-dimensional and multidimensional arrays with memory representation.
- Derive row-major and column-major address calculation formulas.
- Explain sparse matrices and their three-tuple representation.
- Explain singly linked lists and their operations with algorithms.
- Explain doubly linked lists with insertion and deletion operations.
- Explain circular linked lists and their applications.
- Compare arrays and linked lists.
- Explain polynomial representation using linked lists.
- Write an algorithm for polynomial addition using linked lists.
- Explain polynomial multiplication using linked lists.
Explore More Resources of Data Structures
| Resource | Description | Link |
|---|---|---|
| Data Structures Question Bank | Practice important questions, MCQs, and exam-oriented questions on Data Structures. | Data Structure Previous Year Questions and Answers → |
| Data Structures Previous Year Question Papers | Prepare using previous year university question papers for Data Structures. | Data Structure Previous Year Question Papers → |
Explore Other AKTU Data Structures Units Notes
Continue your AKTU Data Structures preparation with complete unit-wise notes, explanations, diagrams, algorithms, and important questions.
| Unit | Topics Covered | Study Notes |
|---|---|---|
| Data Structure Unit 2 | Stacks, Queues and Recursion | Read Unit 2 Notes→ |
| Data Structure Unit 3 | Sorting and searching | Read Unit 3 Notes→ |
| Data Structure Unit 4 | Graphs and Graph Algorithms | Read Unit 4 Notes→ |
| Data Structure Unit 5 | Trees and Binary Trees | Read Unit 5 Notes→ |
Explore more AKTU B.Tech CSE notes, syllabus, and examination preparation resources on Quescol.