Tag Archives: Linked List

Convert a Binary Tree to Doubly Linked List

You are given a Binary Tree. Your task is to convert it into a doubly-linked list. The left and right child of the nodes of the Binary Tree is to be converted into previous and next pointers of the linked list respectively. Nodes of the doubly linked list must be according to the inorder of the binary tree.… Read More »

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 Doubly Linked List

A circular doubly list is a combination of doubly and circular lists; it inherits the properties of both the data structures. Consequently, this makes circular doubly quite complex. Similar to a circular linked list, performing traversing in the circular doubly linked list could lead to an infinite loop. Thus, you need to be extra careful while writing the… Read More »