## What is a Linked List ?

A linked list is a linear data structure where each element is known as a node. A node is consist of a pointer and an object. The pointer is pointing to the next node in the list and the object represent the value of the node. There is also a head which is pointing to the start of the Linked List. Following diagram is an example of a Linked List. A...

## How to find length of a linked list in iterative and recursive manners?

As we have already established that Linked Lists are data structures where each element is linked to the other and this linking makes it possible to trace through the data structure. So how would you find the length of a singly linked list? You can do it in two ways. Firstly by iterating through the data structure till the last element. And the sec...

## Insertion in LinkedList at start and at end with examples.

Our LinkedList class looks something like this. It has a Node Class as a inner class which has a next reference to a Node and a integer value. It also has a head Node variable which can be used for various LinkedList operations. It also has a toString method which parses the LinkedList and returns a comma separated value. We will explore this class...

## Reverse a singly linked list in a recursive manner

This one has been an interview favourite for quite some time now. The trick is to break the operation into smaller operations and extract the common logic. In such a case it makes sense to go till the last 2 nodes and begin the reversal there. We call the method with the node in question and its previous node so that when we identify that the node ...

## Reverse a Singly Linked List

Singly Linked Lists are a type of data structure. It is a type of list. In a singly linked list each node in the list stores the contents of the node and a pointer or reference to the next node in the list. It does not store any pointer or reference to the previous node. package com.tuturself.programs; public class SingleLinkedList < T > { ...

## Given a Linked List. Write a Program to retain n elements and delete m elements till the end of the List.

Consider a Linked List is given to you. And you have to retain n elements and delete m elements till the end of the List. To understand the problem with more clarity consider the following example. Input: N = 1, M = 1 Linked List: 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 → 9 → 10 Here you have to retain 1 element and delete 1 element till the end of the Lin...

## We have a singly-linked list and want to check if it contains a cycle

The difference between a regular LinkedList and a LinkedList with a Loop is that, There are two nodes in a LinkedList with a loop whose next pointers are the same. In a regular single LinkedList (without a loop) each node’s next pointer is unique. So the repeatation of next pointer in a LinkedList is actually indication of a loop. Following figure ...

## Write a function to check if 2 LinkedList intersecting each other ?

Suppose there are two singly linked list both of which intersect at some point and become a single linked list. The head and start pointers of both the lists are known, but the intersecting point is not known. Also, the number of nodes in each of the list before they intersect is not known and may be different in each list. Consider list1 may have ...

## How to find the nth Last node of a Singly LinkedList ?

Generally, LinkedList means a Singly LinkedList. This list consists of a number of nodes where each node has a next pointer to the following node. The link of the last node in the list is NULL, which indicates the end of the list. Following figure describes such a singly LinkedList. Following is the type declaration we are going to use for our exam...

## Find the start point of a Loop in a Singly LinkedList if there is any Loop?

In this article we are going to find the node in a singly LinkedList, where a Loop starts , if there is a loop exists in the LinkedList. The solution is a extension to the problem of finding the existence of a Loop in a linked list. Finding the loop in a linked list was solved using Floyd cycle detection algorithm in this article. It is highly reco...

## How to check if a singly linked list is palindrome or not ?

Given a singly linked list , we need to write a function that returns true if the given list is palindrome, else false. Consider the following figure of a linked list which is an example of palindrome. Following is the linked list ADT we are going to use for this article. First let us declare the Node.Java , which is representing a single node in t...

## Merge Two Sorted Linked Lists

Write a merge function that takes two lists, each of which is sorted in increasing order, and merges the two together into one list which is in increasing order. The merge should return the new list. The new list should be made by splicing together the nodes of the first two lists. Following is the Linked NODE and LinkedList ADT we are going to use...