Objec­tive: Write an algo­rithm to imple­ment Stack using Linked List. If you do not know about then for starters its abstract data type in which fol­lows the prin­ci­ple of LIFO (Last-In-First-Out) which means the…

In this arti­cle we will see what is dou­bly linked list, how it is dif­fer­ent from other linked list and how to imple­ment it. Ear­lier we have seen what is Singly Linked List and Circular…

Ear­lier we have seen what is Singly Linked List and How to imple­ment it. In a way you say that it’s an exten­sion of singly linked list. I would sug­gest that if you do…

Objec­tive: Given a linked list write an algo­rithm to swap nodes in pairs by chang­ing links . Ear­lier we have seen “Swap Every Kth node in a Linked List”, where we have seen how to…

Reverse Alternative ‘k’ nodes in a Linked List.

Objec­tive: Given a linked list and a num­ber ‘k’, write an algo­rithm to reverse alter­nate ‘k’ nodes in the linked list. This prob­lem was asked in the Microsoft and Ama­zon inter­views. Exam­ple: Approach: Recursion…

Reverse a Linked List in groups of given size ‘K’

Objec­tive: Given a linked list and inte­ger ‘k’, write an algo­rithm to reverse the linked list in groups of size ‘k’. Exam­ple: Approach: Ear­lier we have seen how to reverse a linked list, solu­tion for…

Alternate Splitting of a given Linked List

Objec­tive: Given a singly linked list, split it into two linked lists. These linked lists will con­tain the alter­nate nodes from the given linked list. Example:

Objec­tive: Reverse The Dou­bly Linked List. Example:

Swap Kth Node from the front with the Kth Node from the End

Objec­tive: Given a Linked List and a num­ber k, Swap Kth Node from the front with the Kth Node from the End Exam­ple: ->10->20->30->40->50->60->70 Swap­ping 1 Node from the Front and from the End ->70->20->30->40->50->60->10…

Delete X Nodes After Y Nodes In a Linked List

Objec­tive: Given a Linked List and x and y. Delete x num­ber of nodes after y nodes from the start. Exam­ple: ->10->20->30->40->50->60->70->80->90->100->110->120 Deleted 4 Nodes after 5 Nodes ->10->20->30->40->50->100->110->120 Approach:

Merge Sort in a Linked list

Objec­tive: Given a Linked List, Sort it using merge sort. Exam­ple: ->9->3->4->2->5->1 Sorted List: ->1->2->3->4->5->9 Approach: Ref­er­ence : Merge Sort in array

Objec­tive: Given two linked lists, merge one list into another at alter­nate posi­tions, if sec­ond link list has extra nodes, print them as well Exam­ple: 5 -> 10 -> 15 -> 20 ->25 -> null…

BST.">Convert a Sorted Doubly Linked List to Balanced BST.

Objec­tive: Given a sorted dou­bly linked list, con­vert it into Bal­anced binary search tree Input: A Dou­bly Linked List Exam­ple: Approach:

In a Binary Tree, Create Linked Lists of all the nodes at each depth.

Objec­tive: Given a Binary tree cre­ate Linked Lists of all the nodes at each depth , say if the tree has height k then cre­ate k linked lists. NOTE : This prob­lem is very…

FORWARD order">Add two numbers represented by a linked list, Numbers are Stored in FORWARD order

This post is the exten­sion of   — Two num­bers rep­re­sented by a linked list, Num­ber Stored in REVERSE order Objec­tive: Two num­bers rep­re­sented by a linked list­where each node con­tains sin­gle digit. The digits…

REVERSE order">Add two numbers represented by a linked list, Numbers are Stored in REVERSE order

We have sim­i­lar post — Two num­bers rep­re­sented by a linked list, Num­ber Stored in FORWARD order Objec­tive: Two num­bers rep­re­sented by a linked list where each node con­tains sin­gle digit. The dig­its are…

Reverse a Linked List — Part 2

This post is the exten­sion of our ear­lier post Reverse a linked list. Here We have pro­vided the bet­ter recur­sive solu­tion in which we start revers­ing the list from the end. Objec­tive: Reverse the…

Swap Every Kth Node in a LinkedList

Objec­tive: Given a linked list, swap every kth node in that. If at the end of the list remain­ing nodes are less than k, leave them untouched. Input: A linked list, A num­ber k. Example:…

Objec­tive: Write a pro­gram to Delete a Node in the Mid­dle of a linked list, Given only access to that Node Exam­ple: Orig­i­nal List : ->1->2->8->3->7->0->4 After Delet­ing the mid node (say 7) : ->1->2->8->3->0->4…

Find the n’th Node from the end of a given Linked List

Objec­tive: Given a linked list and inte­ger ‘n’, write an algo­rithm to find the nth node from the end in the Linked List. Exam­ple: Orig­i­nal List : ->1->2->8->3->7->0->4 Out­put : 3rd Ele­ment from the…

Remove Duplicates from an Unsorted Linked list

Objec­tive: Write a pro­gram to remove the dupli­cates from an unsorted linked list Exam­ple: Input Linked List : 1->2->2->4->3->3->2 Out­put : 1->2->4->3 Input: An unsorted linked list Out­put: Linked list with no dupli­cates. Approach:…

Find Intersection Point in Two Linked List

Objec­tive: Given Two linked list, check whether both list inter­sect each other, if yes then find the start­ing node of the inter­sec­tion. Inter­sec­tion point means end of one linked list is linked with some…

Find the Loop in a Linked list, find its length and Break the Loop

Objec­tive: In a given linked list, check whether it con­tains the loop in it, if yes then find the Loop length and break the loop. Loop in a linked list means the last node does…