start allocate memory for the new node and initialize its data part to add the new node as the first node of the list by making the next part of the new node contain the address of start start now make start to point to the first node of the list start figure inserting an element at the beginning of linked list step if avail null write overflow go to step [end of ifstep set new_node avail step set avail avail -next step set new_node -data val step set new_node -next start step set start new_node step exit figure algorithm to insert new node at the beginning figure shows the algorithm to insert new node at the beginning of linked list in step we first check whether memory is available for the new node if the free memory has exhaustedthen an overflow message is printed otherwiseif free memory cell is availablethen we allocate space for the new node set its data part with the given val and the next part is initialized with the address of the first node of the listwhich is stored in start nowsince the new node is added as the first node of the listit will now be known as the start nodethat isthe start pointer variable will now hold the address of the new_node note the following two stepsstep set new_node avail step set avail avail -next these steps allocate memory for the new node in cthere are functions like malloc()allocand calloc(which automatically do the memory allocation on behalf of the user inserting node at the end of linked list consider the linked list shown in fig suppose we want to add new node with data as the last node of the list then the following changes will be done in the linked list figure shows the algorithm to insert new node at the end of linked list in step we take pointer variable ptr and initialize it with start that isptr now points to the first node of the linked list in the while loopwe traverse through the linked list to reach the last node once we reach the last nodein step we change the next pointer of the last node to store the address of the new node remember that the next field of the new node contains nullwhich signifies the end of the linked list inserting node after given node in linked list consider the linked list shown in fig suppose we want to add new node with value after the node containing data before discussing the changes that will be done in the linked listlet us first look at the algorithm shown in fig