 Hello friends. I am Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. In this video, I'm going to discuss about sparse metrics. So after watching this video, you will get familiar like what sparse metrics is and how sparse metrics is represented in memory. Before starting, if you want to watch more videos based on data structures and algorithm, so you can go to description of this video and you will find links of playlist and you can follow them so that you can watch videos related to data structure. So now here I'm just explaining the concept of sparse metrics. So a matrix basically is a two dimensional data object made of m rows and m columns. So therefore having total m into n values. So this is about a simple matrix. Now if most of the elements of the matrix have zero value, then it is called a sparse metrics. So here you can see an example. So in this matrix, we have more zeros as compared to non zero elements. So this kind of matrix is known as sparse metrics. But if we want to store sparse metrics in memory so we don't store all the values like zeros and non zeros, we just focus on the non zero elements. So why to use sparse metrics? So there are two advantages. First is storage and second is computing type. So if you ignore zeros, then you just need to store the non zero elements. So there are lesser non zero elements than zeros. Thus lesser memory can be used to store only those elements. So we will be storing only non zero elements and their row and column indexes and other indexes will be automatically treated as zero. Second is computing time. So whenever we will be applying any computation, so computing time can be saved by logically designing a data structure, traversing only non zero elements. So if we implement sparse metrics in such a way like we can have less amount of memory to store the values and we can improve computation time. So this can be done with the implementation of sparse metrics with the help of array and link the representation and they will be storing all the non zero elements. So now I'm going to tell you how we can represent sparse metrics in memory. So representing a sparse metrics by a 2D array needs two bases of nodes of memory as zeros in the matrix are of no use in most of the cases. So if you store sparse metrics as it is, like if you store zeros as well as non zeros in memory, so you will see you will base large amount of memory because if you are storing zeros unnecessarily, then that is not required. You can just store the non zero elements only, right? So instead of storing zeros with non zero elements, we only store non zero elements. This means storing non zero elements with triples like row index of non zero value, column index of non zero value and the value itself. So sparse metrics representations can be done in following two ways. First is array representation and second is then the list representation. So this is the array representation which is quite easy. So instead of storing zeros and non zeros together we just store the information related to non zero elements. So this is also a 2D representation where first row is having all row indexes, second is having column indexes and third row is having values. So let's say if we talk about this three, so it's row index is zero and column index is two that is stored here. So zero two and actual value is three. So here you can see we are storing information related to non zero elements only and we are skipping the information of zeros because if we have index row and column in this 2D array, it means that index is having non zero element. And if the index is not in the 2D array, it means that position is having zero. So we can easily calculate that while implementing the logic. So let's say if you have 100 by 100 2D array, so you need to store 10,000 values and in those 10,000 values you have only 500 non zero elements. So don't allocate 100 by 100 metrics, just create this kind of representation to store only non zero elements. So this will save a lot of memory and competition time as well. So second one is linked list representation. So it is also having a row index, column index and value. Apart from that, in linked list we have fourth option in form of next node. So that will be storing address of the next node. So in case of linked list we have various nodes. So this is node one, this is node two, this is node three and so on. So each node will be having information related to one non zero element. So here you can see first block is having zero which is row index, second block is column index, third block is value itself and fourth is having the address of next node. So in case of 2D array, memory is allocated altogether but in case of linked list each node will be having memory at a particular place. Like they all node may not be having memory allocated on the same location. So they are connected via addresses. So that's why this whole location is required. So if you want to implement a C program based on this linked list representation, so you need to create a structure. So node structure will be unique to a particular row, variable, column variable, value variable and a pointer that will hold the address of the next node. So this way you can reduce large amount of memory to stores pass matrix non zero elements only. So I explained you two representation of pass matrix. One is array representation and second one is linked list representation. So I hope you understood the basic information or basic requirement related to pass matrix. And if you want to watch more data structures and algorithm related videos, you can go to description of this video. You will find link of playlist follow that and I also uploaded videos related to BSA implementation using C like this so you can watch that too. So thank you for watching this video.