Find Middle Element of a Linked List – Java Code

In this tutorial, Let’s discuss how to find middle element of a linked list in a single traversal.

Given a singly linked list, write a code to find middle element in a linked list.

For example: Given a linked list, the middle element in this linked list is 8.

15 -> 9 -> 8 -> 5 -> 6 -> NULL

This type of questions are generally asked in an interviews.

There are multiple approaches to solve this problem. In this tutorial, I am going to discuss two approaches through which we can find the middle element of a singly linked list in one pass.

I have also added video tutorial at the end of this post.

Programming video tutorials

Insertion Sort Program in Java

Insertion Sort Program in Java. Write a java program to sort an unsorted array using insertion sort.

In this tutorial, We are going to cover following points.

  • How insertion sort works?
  • Insertion sort program in java.
  • Video tutorial which explain insertion sort algorithm.

Let’s say we have an unsorted array and we want to sort this array using insertion sort. Let’s first understand how insertion sort works?

Input : {5, 4, 2, 9, 1}

Output : {1, 2, 4, 5, 9}