Space matrix Space_Matrix_in_Data_Structures.pptx

Bhagyashree259318 0 views 11 slides Oct 13, 2025
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

🧮 Space Matrix in Data Structures

A space matrix (or sparse matrix) is a type of matrix that has most of its elements as zero (0) and only a few non-zero elements.
Since storing all zeros wastes memory, special representations are used to save only non-zero elements, making it memory-efficient.
...


Slide Content

Space Matrix in Data Structures A matrix is a two-dimensional array of numbers arranged in rows and columns. When most of the elements are zero, it is called a Sparse Matrix.

Types of Matrices 1. Dense Matrix - Most elements are non-zero. 2. Sparse Matrix - Most elements are zero. Example Sparse Matrix: [5 0 0] [0 0 8] [0 0 0]

Why Sparse Matrix Representation? Storing all elements (including zeros) wastes memory. We store only non-zero elements along with their row and column positions.

Triplet Representation Each non-zero element is represented by: - Row index - Column index - Value Example: Row | Col | Value 0 | 0 | 5 1 | 2 | 8

Array of Structures Representation struct Element { int row; int col; int value; }; struct Sparse { int rows; int cols; int num; struct Element *e; };

Linked List Representation Each node represents a non-zero element and stores: - Row index - Column index - Value - Pointer to next node struct Node { int row, col, value; struct Node *next; };

Example Program in C #include <stdio.h> #include <stdlib.h> struct Element { int row, col, value; }; int main() { struct Element sparse[] = { {0, 0, 5}, {1, 2, 8} }; int size = 2; printf("Row Col Value\n"); for (int i = 0; i < size; i++) { printf("%d %d %d\n", sparse[i].row, sparse[i].col, sparse[i].value); } return 0; }

Advantages - Saves memory - Faster operations with non-zero elements - Useful for large, sparse data structures

Disadvantages - Complex implementation - Slower access compared to normal 2D arrays

Applications - Graph representation (Adjacency matrix) - Image processing - Optimization problems - Machine learning weight matrices

Conclusion Sparse Matrix efficiently stores matrices with many zeros. By saving only non-zero elements and their positions, it reduces memory and improves performance.
Tags