Tag Archives: Linked List

Merge Sort for Linked Lists

There are a plethora of sorting algorithms present for arrays like the bubble sort, insertion sort, selection sort, heap sort, merge sort, quick sort, and many more. But in the case of Linked Lists, the implementation of all the sorting algorithms is difficult. Heapsort is totally impossible for sorting the linked list. In this article, we will discuss… Read More »

Reverse a Linked List

Linked List is one of the most important data structures in computer science due to several reasons. The most important one is the drawbacks of the array data structure. Deletion of the elements of the array data structure is highly in-efficient and requires a very time-consuming process. Linked list overcomes this drawback as well as many other drawbacks… Read More »

Clone a Singly Linked List

You are given a singly linked list, having n nodes in it with each node having a pointer that is pointing to the succeeding node of the linked list. Your task is to clone the entire linked list and return a new copy of the given linked list. Example 1: Output: 1->2->3->4->5 Explanation: The cloned linked list will… Read More »

Clone a Linked list with the Random Pointer

Given a linked list, in which every node contains the next pointer. They also contain an additional random pointer that is pointing to any random node present in the linked list or a null pointer in the linked list. We have to make a clone of the given Linked list that contains exactly the same number of nodes… Read More »

How to find and remove loops in a Linked List?

Question Given a Linked List, how can you detect and remove a loop from that linked list efficiently? Sample Test Cases: Test Case 1 Sample Input Expected Output 13–>24–>26–>38–>41–>NULL. Test Case 2 Sample Input Expected Output 55–>45–>54–>63–>56–>NULL Test Case 3 Sample Input Expected Output 7–>9–>8–>6–>NULL Explanation As the problem states, we need to find a loop in a… Read More »

Circular Linked List

As we know that a Simple linked list is a sequential collection of Nodes, and each node has a data value and a pointer variable which hold the address of the next node.  A Circular linked list is similar to Simple linked-list the only difference is, here the pointer variable of the last node point to the head… Read More »

Doubly Linked List

Doubly Linked List is an extension of Linked List in which we have two pointer variables, so we could traverse back and forth directions. It contains two pointers conventionally named, next and prev, in next we store the address or object of next element or node and in prev, we store the address of the previous object.