linked-list

Detect Loop in Linked List (Floyd's Cycle Detection Algorithm)
Detect Loop or Cycle in Linked List

Given the head of a linked list, write a program to find if linked list has a cycle or not. Return true if there is a cycle or loop in the linked list. Otherwise, return false. A linked list with cycle causes iteration to fail because the iteration will never reach the end. So, detecting a linked list loop is important before applying an iterative approach.

Intersection of Two Sorted Linked Lists
Intersection of Sorted Linked Lists

Write a program to find intersection of two sorted linked lists and return the head pointer of the new linked list. Here head pointers of both sorted linked lists are given as input and we shouldn’t do any changes in the structure to generate the output. Note: This is an excellent problem to learn problem-solving using recursion and two pointers in a linked list.

Remove nth node from end of list
Remove nth node from end of list

The head pointer of a linked list is given. Write a program to remove the Nth node from the end of the linked list and return its head. In other words, when the node is traversed from the end, we have to delete the Nth node from there. Note: This is an excellent problem for beginners to learn problem-solving using two pointers in a linked list.

Reverse a Linked List
Reverse a Linked List

A head pointer of a singly linked list is given, write a program to reverse linked list and return the head pointer of the reversed list. We need to reverse the list by changing the links between nodes. Note: This is an excellent question to learn problem-solving using both iteration (Three-pointers) and recursion (Decrease and conquer approach).

Find Middle of the Linked List
Middle of the Linked List

Given a singly linked list, write a program to find the middle element of the linked list. We need to return the second middle node if the node count is even. The goal should be to use a single loop and O(1) extra space to find the middle element. Note: This is an excellent problem to learn problem-solving using fast and slow pointers in the linked list.

Sort Linked List using Insertion Sort Algorithm
Insertion Sort Linked List

We have given the head of a singly linked list, write a program to sort the list using insertion sort, and return the head of the sorted linked list. To implement this algorithm, we need to understand the idea of insertion sort on array. At each step of the iteration, insertion sort adds one element to the sorted output and grows the partially sorted list size by 1.

Swap Linked List Nodes in Pairs
Swap List Nodes in Pairs

Given the head pointer of a singly linked list, write a program to swap nodes in pairs and return the head of the modified linked list. If the number of nodes is odd, then we need to pairwise swap all nodes except the last node. Note: This is an excellent problem to learn problem solving using both iteration and recursion in a linked list.

EnjoyAlgorithms Newsletter

Subscribe to get well designed content on data structure and algorithms, machine learning, system design, object orientd programming and math.

Follow us on

©2023 Code Algorithms Pvt. Ltd.

All rights reserved.