 that is on q using linked list. Learning outcomes at end of this session, students will be able to explain q using linked list in data structure. So before starting with the linked list, so let us have the introduction about the linked list. So in the previous two videos, we have seen the implementation of the q that is a linear q and the circular q. So the q was implemented using an array. So now due to the efficient use of memory utilization, we are going to use the q for the implementation using a linked list. So let us understand what do you mean by a linked list? Okay, so we'll start with the introduction. A linked list is a linear collection of data elements called nodes, where the linear order is implemented by means of pointer, each node contains a two types of field. That is, the first field contains the information of the elements. And the second field contains the address of the next node in the list. Suppose, as shown in this figure, this is known as an the node where it has the two information that is one is that is the first field is the information either it may be integer value or the characters or the whatever you want to store, you are going to have the information storing this like and data and the next which holds the address of the next node. If it is only the one node, then we have to point through and null here means that is the termination of an linked list here. If it is having one more node connecting to this here. So what do I have to do we have to write the address of the next node. Okay, so this was about the nodes here. Now we'll see the types of linked list here. So there are three types of linked list. First one is your singly linked list. Second one is your doubly linked list. And the third one is your circular linked list. So as we told in the first slide, so if you are going to have the one more node connected to the first node here, so the address of this node is stored into next value here, and it is being connected. And this is the last node in the list. So that's why we have to write here null or terminating node here. Okay, so every time whenever we are going to terminate the list, we have to mark it with a null. Similarly, if you're going to make use of an doubly linked list, so you're going to have these type of node here that is an information here. And the next the address of the next node and here the previous address of the node here means in the singly linked list and the doubly linked list, the difference is what in doubly linked list, we are going to store the previous address of the node here. So what is an added advantage here? So you can jump from the one place to another in the forward direction as well as in the backward direction here means in singly linked list, we can jump only in the forward direction only if you're in somewhere in the middle of the list. If you want to come back to search the data or delete the data, once again, we have to start from the first node only. So that is an time consuming. In the same manner, the added advantage is what? So you can jump to the previous nodes for searching and deleting and you can jump to the next node also. But what is the disadvantage? It uses more memory than the singly linked list here, the information is there and the two pointers are used to store the next and the previous address here. Now we are going to see the circular linked list. It is just like a link linear linked list in which the second part of the last node contains the address of the first in the list. That is the second field of the last node does not point to the null pointer, rather it points back to the beginning of the linked list means what? So here what we have seen that is it is going to point towards the next node. Here we have seen the it is pointing towards the next node and the previous node. And if you want to terminate this linked list, we have to mark with the null node. But in circular linked list, there will be no last node here. So that's why there will be no null node here. Okay, so what will happen? So it will point towards the first node here means here in last node of the circular linked list, the address of the first node is stored here means it will jump from this location to this location, this location to this location and this location will store the address of the this location. So that's why it is known as a circular linked list. But it is just like a linear linked list here. So what are the advantages of using a linked list over an array? So the linked list are the dynamic data structure. That is second one is what you are the efficient memory utilization, insertion and the deletions are easier and efficient and easy for the complex application. So what do you mean by this insertion and deletions are easier and effective? And the linked list are dynamic data structure means you can increase the size of an list and decrease the size of the list at the runtime here. So in array, whenever you're going to allocate the memory, it is memories allocated at the compile time only. So if you want to increase the size of an array, you cannot increase the size of an array at the runtime here. If you want to decrease the size of an array to use the effective memory utilization, we cannot decrease that. But in linked list, we are going to make use of a dynamic data structure. So that's why we can increase or shrink the list at the runtime here. So if you do that, that is known as an effective memory utilization. Now insertion and deletions are easier and efficient means what? So if you are using an array, if you want to delete the element in between the array, so we have to go to that place and delete that. And again, once again, we have to shift the other elements to the previous location. So it becomes tedious. But in the linked list, what we have to do if you delete the elements in between the two linked list. So what we have to do, we have to just connect the previous nodes address to the next node here. So there is an insertion and deletion are becomes easy, and it is useful for the complex applications. So array is not useful for the complex application. So this is the representation of a linked list. So this is the structure defined for the linked list implemented here. Now suppose if you are going to make use of a single linked list, which has only the two information that is first field contains the information, the second field contains the address of the next node if you want to write in the structure. So that is written in this manner that is struck node int data, which where the information is stored in that field, and the second node struck node next which holds the address of the next node here. So this is this struck node has been defined for the single linked list. If it is used for the double linked list, what we have to do one more point we have to add that is a struck node star previous means to store the address of the previous node here. And how you're going to increase or shrink the list at the runtime here. So there are two functions that is malloc and callocs are used to create the node at the runtime. Okay, if you want to make it free, then you have to make use of an free function means that if you are allocating more memory at the runtime and you are not going to use that memory. So you can make use of an free function to decrease the size of an memory here means what whenever you are required the memory at that time you can allocate that memory by using malloc and calloc functions. And you can make it free also if you don't want. Okay, so that is an advantage of using an linked list or an array here. So now we'll see the implementation of Q using a linked list. So up till now what we have seen, the queue was implemented using an array. So in array, we cannot increase or decrease the size of an queue at the runtime here. So that disadvantage has been removed using an linked list here in queue is implemented first in first out that this is the same thing we have to implement using a linked list also that is first in first out here. Okay, in queue, we have seen that two operations that is nq and dq operations. In nq operations, we have to check the full condition that is an overflow condition. And in dq operation, we are going to check an empty condition that is an underflow condition. But when you are going to implement the queue using linked list, there is no full condition because you can allocate the memory as the compiler will allocate that. So there are infinite number of memory is allocated here. There is no tension to have how many memories allocated to you use here. So there will be no full condition during an the nq operation. But while doing an dq operation, we have to check an empty condition because is there any linked list present in the queue? Okay, so we'll start with the implementation of an queue using an linked list. The linked list, the representation of queue does not have any restriction on the number of elements it can hold here. The elements in the linked list are allocated dynamically. Hence, it can grow as long as there is sufficient memory available for the dynamic allocation here. So that is an advantage here. In the same manner, what we have seen in the previous video that is the nq operation, dq operation and the display operation for the queue. In the same manner, we have to implement the queue using an linked list. Here, we have to make use of an pointer which holds the address of the next node here. So before starting to this lecture, you should be able to understand how the pointers are going to work. So we'll start with an algorithm that is an insert an element into the queue. So we can use the following steps to insert the new node into the queue here. So what is the first step in the same way in the queue what we used to do in the linear queue we used to directly insert here. So here first step in the queue is what we have to create the new node here. That is one node you have to create with a given value. Suppose we have taken the value of 10. So that will be the node 10. And the set the new node to the next it is pointing towards the next to the null. And then check whether the queue is empty. So how you are going to check that is rare is equal to equal to null here also the same two pointers are used to track the record of nq that is front pointer and the rare pointer here. Yeah, that is if the queue is an empty, then you have to see that rare is equal to equal to null. If it is empty, then front set front equal to new node and the rare is equal to new node. Okay, next step is what if it is not empty, then set rare of next equal to new node and rare is equal to new node here means the new node will be allocated at that time here. Now, if you want to delete an element from the queue what we have to do these are the following steps we have to perform check the weather queue is empty or not. So in the previous thing inserting we are not going to check the full condition here so directly you can insert the new node here every time here so there is no necessary that you are going to check the full condition here but we have to check the empty condition is there any list in the queue to delete that. So first check that condition how you are going to check that front is equal to equal to null. If it is empty then display queue is an empty step three is what if it is not empty then define node pointer temp where temp one variable you are going to take and set it to the that is front then then set front is equal to front of next and delete them means temp is required to delete that element from the queue here that is free time this is a function used to free that node here. Okay, so this is an the algorithm useful to write an and deleting an element from the queue. Next, if you want to display the elements in the queue, so in the same manner, is there any node in the queue? So for that we have to check whether the queue is empty. If it is empty, so you cannot display if queue is an empty and terminate that function. If it is not empty, then the node pointer temp is initialized with the front pointer and display temp of data is equal to temp and move to the next node. Repeat the same until the time reaches to the rare that is temp of next is not equal to null. And step five is what the display temp of data is equal to null. So in this manner, if you write an algorithm for this, you can have the displaying of the element of a queue. So these are the my references and thank you.