Java icon indicating copy to clipboard operation
Java copied to clipboard

Add "Find Middle of a Singly Linked List" Algorithm and Tests

Open Hirannya-Mhaisbadwe opened this issue 2 months ago • 8 comments

What would you like to share?

I noticed that the project currently does not include an algorithm for finding the middle of a singly linked list, nor are there any unit tests for this operation.

Proposed Solution:

Implement a function to find the middle node of a singly linked list using the slow and fast pointer technique.

Ensure the function works for both odd and even-length lists (document whether it returns the first or second middle for even-length lists).

Add unit tests to verify correctness for various list lengths and edge cases.

Include proper documentation and comments explaining the approach.

Motivation / Benefits:

Finding the middle of a linked list is a fundamental operation used in many algorithms, such as:

Merge Sort on linked lists

Checking if a linked list is a palindrome

Reordering or splitting linked lists

Adding this algorithm will improve the completeness and educational value of the linked list module.

References:

Slow and Fast Pointer Technique (Floyd’s Tortoise and Hare) LeetCode 876 – Middle of the Linked List: https://leetcode.com/problems/middle-of-the-linked-list/

Additional information

No response

Hirannya-Mhaisbadwe avatar Oct 04 '25 10:10 Hirannya-Mhaisbadwe