Handling 2 pointer

Ma’am here why we use 2 pointer… Can I do it using only one pointer I.e., head only to add element at last in the linked list?

@amanchowdhury0123,

Yes you can do it using only the head node to add element at last in the Linked List but it will be a computationally expensive operation. Because everytime you need to add a node, you will have to traverse the entire Linked List first and then add the node.

For example you have a linked list of size 1000, and you want to add a new element at last. Now you will have to traverse the entire Linked List and only when you reach the 1000th element you can add a new element.

2 pointer approach makes it simpler and the entire operation because computationally cheaper because now you simply need to add a new node after the tail node and update the tail node. You don’t have to traverse the entire Linked List.

I hope this helps, if in case you have more doubts feel free to respond to this thread. Thanks! :smile: