Home » AKTU CSE Notes » AKTU Data Structure Unit 1 Notes KCS 301

AKTU Data Structure Unit 1 Notes KCS 301

Last updated:

Support this post with a reaction:

3,378 views

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:

  1. Efficient data storage: Organize data in a structured manner.
  2. Fast data access: Enable efficient retrieval of information.
  3. Memory optimization: Use available memory effectively.
  4. Easy data manipulation: Support insertion, deletion, and modification.
  5. Improved performance: Reduce execution time for operations.
  6. Handling complex data: Represent hierarchical and interconnected information.
  7. Reusability: Support reusable algorithms and software components.

Basic Operations on Data Structures

OperationDescription
TraversalVisiting each element of a data structure
InsertionAdding a new element
DeletionRemoving an existing element
SearchingFinding a specific element
SortingArranging elements in a particular order
MergingCombining two data structures
UpdatingModifying an existing element

Classification of Data Structures

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 as 10, 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 as 10.5 or 25.75.
  • double: Used to store decimal numbers with double precision, providing more accuracy than float.
  • 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 StructuresNon-Linear Data Structures
Elements are arranged sequentiallyElements are arranged hierarchically or interconnected
Each element generally has a predecessor and successor, except endpointsAn element may have multiple connections
Traversal is usually sequentialTraversal may follow multiple paths
Examples: Array, Linked List, Stack, QueueExamples: 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 TypePurposeExample
intStores integer valuesint age = 20;
charStores a characterchar grade = 'A';
floatStores single-precision floating pointfloat marks = 85.5f;
doubleStores double-precision floating pointdouble pi = 3.14159;
voidRepresents absence of a valuevoid 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

  1. short – Specifies a shorter integer type, such as short int. The C standard sets a minimum range. It does not guarantee that every compiler stores short in fewer bytes than int.
  2. long – Specifies a longer integer type, such as long int. A compiler may store it in more bytes than int, but that size is not the same on every system.
  3. signed – Allows a variable to store both positive and negative values.
  4. 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:

  1. Input: An algorithm accepts zero or more input values to perform a task.
  2. Output: It must produce at least one output or result.
  3. Definiteness: Every instruction must be clear, precise, and unambiguous.
  4. Finiteness: An algorithm must terminate after a finite number of steps.
  5. Effectiveness: Every instruction in an algorithm must be sufficiently basic, precise, and executable in a finite amount of time using available resources.
  6. 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.

Flowchart: Find the Largest of Two Numbers

Common Flowchart Symbols

Flowchart symbols are standard graphical representations used to describe different steps and operations in an algorithm or process.

SymbolNamePurpose
OvalTerminalRepresents the Start or End of a flowchart.
RectangleProcessRepresents calculations or processing operations.
ParallelogramInput/OutputRepresents data input or output operations.
DiamondDecisionRepresents a condition with Yes/No or True/False branches.
ArrowFlow LineIndicates 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:

  1. Input Size: Larger input data may require more processing time and memory.
  2. Algorithm Design: A well-designed algorithm generally performs fewer unnecessary operations.
  3. Data Structure Selection: Choosing suitable data structures, such as arrays, linked lists, stacks, or hash tables, can improve performance.
  4. Hardware Architecture: Processor speed, RAM, and system architecture can affect execution performance.
  5. Programming Language and Compiler: Language features, compiler optimizations, and runtime environments can influence execution speed.
  6. Number of Operations: The number of comparisons, calculations, and iterations affects execution time.
  7. 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 10 is 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, and 40.
  • Finally, it checks 50 and 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:

  1. Base Case: The condition that stops the recursion.
  2. 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);
}
IterativeRecursive
Uses loopsUses function calls
Usually uses less auxiliary memoryUses call-stack memory
Avoids recursion overheadHas recursion overhead
Suitable for repetitive operationsSuitable 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.

Big O Notation Complexity

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.

ComplexityNameExample
O(1)ConstantAccessing an array element
O(log n)LogarithmicBinary Search
O(n)LinearLinear Search
O(n log n)LinearithmicMerge Sort
O(n²)QuadraticBubble Sort
O(n³)CubicThree nested loops
O(2ⁿ)ExponentialBasic recursive subset generation
O(n!)FactorialBrute-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:

T(n)=n×n=n2T(n)=n\times n=n^2

Time complexity: O(n²).

Example 4: Logarithmic Complexity

while (n > 1) {
    n = n / 2;
}

Each iteration reduces the input size by half.

T(n)=log2⁡nT(n)=\log_2 n

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:

f(n)=O(g(n))f(n)=O(g(n))

Big Omega Notation — Ω

Big Omega notation represents an asymptotic lower bound on the growth of a function.

f(n)=Ω(g(n))f(n)=\Omega(g(n))

Big Theta Notation — Θ

Big Theta notation represents a tight asymptotic bound.

It describes functions that grow at the same order of magnitude.

f(n)=Θ(g(n))f(n)=\Theta(g(n))

Comparison of Asymptotic Notations

NotationMeaningInterpretation
O(g(n))Upper boundGrowth does not exceed a constant multiple of g(n) eventually
Ω(g(n))Lower boundGrowth is at least a constant multiple of g(n) eventually
Θ(g(n))Tight boundGrowth 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:

  1. Data Objects: The collection of data elements stored in the ADT.
  2. Data Relationships: The logical relationships between the data elements.
  3. Operations: The functions or actions that can be performed on the data.
  4. 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};
Arrays

Characteristics of Arrays

  1. Stores homogeneous elements.
  2. Uses contiguous memory locations.
  3. Supports direct access using indices.
  4. Has a fixed size in standard fixed-size array declarations.
  5. Supports efficient traversal.
  6. 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.

One-Dimensional Array

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];
Two-Dimensional Array

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:

2×3×4=24 2\times3\times4=24

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:

  1. Row Major Order
  2. 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:

A[3][3] A[3][3]

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:

LOC(A[i][j])=BA+[(i−L1)×N+(j−L2)]×w LOC(A[i][j]) = BA+[(i-L_1)\times N+(j-L_2)]\times w

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:

LOC(A[2][1])=1000+[(2−0)×3+(1−0)]×4 LOC(A[2][1]) = 1000+[(2-0)\times3+(1-0)]\times4

=1000+[6+1]×4 =1000+[6+1]\times4

=1000+28 =1000+28

1028 \boxed{1028}

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:

A[3][3] A[3][3]

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:

LOC(A[i][j])=BA+[(j−L2)×M+(i−L1)]×w LOC(A[i][j]) = BA+[(j-L_2)\times M+(i-L_1)]\times w

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:

LOC(A[2][1])=1000+[(1−0)×3+(2−0)]×4 LOC(A[2][1]) = 1000+[(1-0)\times3+(2-0)]\times4

=1000+[3+2]×4=1000+[3+2]\times4

=1000+20 =1000+20

1020 \boxed{1020}

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:

i−LB i-LB

Each element occupies w bytes.

Therefore, the offset is:

(i−LB)×w (i-LB)\times w

Adding this offset to the base address:

LOC(A[i])=BA+(i−LB)×w \boxed{LOC(A[i])=BA+(i-LB)\times w}

Example of Index Formulae for 1D Array

Find the address of A[4].

Given:

  • Base address = 1000
  • Lower bound = 0
  • Element size = 4 bytes
LOC(A[4])=1000+(4−0)×4LOC(A[4])=1000+(4-0)\times4

=1000+16 =1000+16

1016 \boxed{1016}

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]:

(i−L1)×n+(j−L2) (i-L_1)\times n+(j-L_2)

Multiplying by element size and adding the base address:

LOC(A[i][j])=BA+[(i−L1)n+(j−L2)]w \boxed{ LOC(A[i][j])=BA+ [(i-L_1)n+(j-L_2)]w }

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]:

(j−L2)×m+(i−L1) (j-L_2)\times m+(i-L_1)

Therefore:

LOC(A[i][j])=BA+[(j−L2)m+(i−L1)]w \boxed{ LOC(A[i][j])=BA+ [(j-L_2)m+(i-L_1)]w }

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:

(i−L1)×n×p(i-L_1)\times n\times p

2. Complete rows before the required row:

(j−L2)×p (j-L_2)\times p

3. Elements before the required column:

(k−L3) (k-L_3)

Adding all three:

LOC(A[i][j][k])=BA+[(i−L1)np+(j−L2)p+(k−L3)]w \boxed{ LOC(A[i][j][k])=BA+ [(i-L_1)np+(j-L_2)p+(k-L_3)]w }

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:

(k−L3)×m×n (k-L_3)\times m\times n

2. Complete columns before the required column:

(j−L2)×m (j-L_2)\times m

3. Elements before the required row:

(i−L1) (i-L_1)

Therefore:

LOC(A[i][j][k])=BA+[(k−L3)mn+(j−L2)m+(i−L1)]w \boxed{ LOC(A[i][j][k])=BA+ [(k-L_3)mn+(j-L_2)m+(i-L_1)]w }

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:

A[d1][d2][d3]…[dn] A[d_1][d_2][d_3]\ldots[d_n]

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:

LOC(A[i1,…,in])=BA+w∑k=1n[(ik−Lk)∏j=k+1ndj] \boxed{ LOC(A[i_1,\ldots,i_n])=BA+w \sum_{k=1}^{n} \left[ (i_k-L_k)\prod_{j=k+1}^{n}d_j \right] }

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:

LOC(A[i1,…,in])=BA+w∑k=1n[(ik−Lk)∏j=1k−1dj] \boxed{ LOC(A[i_1,\ldots,i_n])=BA+w \sum_{k=1}^{n} \left[ (i_k-L_k)\prod_{j=1}^{k-1}d_j \right] }

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:

A=[0amp;0amp;0amp;50amp;0amp;0amp;03amp;0amp;0amp;00amp;0amp;7amp;0]A= \begin{bmatrix} 0&amp;0&amp;0&amp;5\\ 0&amp;0&amp;0&amp;0\\ 3&amp;0&amp;0&amp;0\\ 0&amp;0&amp;7&amp;0 \end{bmatrix}

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:

  1. Data field — stores the value.
  2. 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:

  1. Data: Stores the actual value.
  2. 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.

Singly Linked List

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.
Doubly Linked List

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:

  1. At the beginning of the list.
  2. At the end of the list.
  3. Before a given node.
  4. 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:

  1. From the beginning of the list.
  2. From the end of the list.
  3. From a specific position.
  4. 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:

  1. Data: Stores the actual value or information.
  2. Next Pointer: Stores the address of the next node.
Circular Linked List

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

FeatureSingly Linked ListDoubly Linked ListCircular Linked List
Pointers per node12Usually 1 or 2
TraversalForwardForward and backwardCircular traversal
Last node linkNULLNULLPoints to first node
Memory usageLowerHigherDepends on type
Deletion of known nodeMay require previous nodeEfficientDepends on implementation
ComplexitySimpleModerateModerate
ApplicationsStacks, basic listsBrowser historyRound-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:

P(x)=anxn+an−1xn−1+⋯+a1x+a0 P(x)=a_nx^n+a_{n-1}x^{n-1}+\cdots+a_1x+a_0

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:

  1. Coefficient: Stores the numerical coefficient of the term.
  2. Exponent: Stores the power of the variable.
  3. 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:

P(x)=5x3+4x2+2x+7 P(x)=5x^3+4x^2+2x+7

Q(x)=3x3+2x2+6x+1 Q(x)=3x^3+2x^2+6x+1

Addition:

P(x)+Q(x)P(x)+Q(x)

=(5+3)x3+(4+2)x2+(2+6)x+(7+1) =(5+3)x^3+(4+2)x^2+(2+6)x+(7+1)

R(x)=8x3+6x2+8x+8 \boxed{R(x)=8x^3+6x^2+8x+8}

Polynomial Subtraction Using Linked Lists

Polynomial subtraction is performed by subtracting the coefficients of terms having equal exponents.

Consider:

P(x)=5x3+4x2+2x+7 P(x)=5x^3+4x^2+2x+7

Q(x)=3x3+2x2+6x+1 Q(x)=3x^3+2x^2+6x+1

Then:

P(x)−Q(x) P(x)-Q(x)

=(5−3)x3+(4−2)x2+(2−6)x+(7−1) =(5-3)x^3+(4-2)x^2+(2-6)x+(7-1)

R(x)=2x3+2x2−4x+6\boxed{R(x)=2x^3+2x^2-4x+6}

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:

(axm)(bxn)=abxm+n (ax^m)(bx^n)=abx^{m+n}

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:

P(x,y)=4x2y+3xy2+5 P(x,y)=4x^2y+3xy^2+5

Q(x,y)=2x2y+6xy2+7Q(x,y)=2x^2y+6xy^2+7

Addition:

R(x,y)=6x2y+9xy2+12 R(x,y)=6x^2y+9xy^2+12

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

ResourceDescriptionLink
Data Structures Question BankPractice important questions, MCQs, and exam-oriented questions on Data Structures.Data Structure Previous Year Questions and Answers →
Data Structures Previous Year Question PapersPrepare 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.

UnitTopics CoveredStudy Notes
Data Structure Unit 2Stacks, Queues and RecursionRead Unit 2 Notes→
Data Structure Unit 3Sorting and searchingRead Unit 3 Notes→
Data Structure Unit 4 Graphs and Graph AlgorithmsRead Unit 4 Notes→
Data Structure Unit 5Trees and Binary TreesRead Unit 5 Notes→

Visit Quescol Home Page

Explore more AKTU B.Tech CSE notes, syllabus, and examination preparation resources on Quescol.