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 5 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

I would like to work on this enhancement issue.

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

kindly assign this issue to me

shafaq16 avatar Oct 04 '25 11:10 shafaq16

Hello, I would like to work on this issue. I've reviewed the requirements of the proposal and I am pretty confident that I will be able to address all of them in my solution. I would be extremely glad if I get a chance to contribute on this one.

avkhalkar avatar Oct 04 '25 13:10 avkhalkar

I am curious to solve this , Can i work on this..?

bunnybhargavi avatar Oct 05 '25 12:10 bunnybhargavi

I want to contribute to this part of the project.

mishikabhandari avatar Oct 07 '25 05:10 mishikabhandari

I would like to work on it.

Approach: I will use Floyd's Tortoise and Hare algorithm. Moving the fast pointer twice, and slow once until the end. Making sure fast covered twice of distance than slow. Slow would be at the middle of the LL. Image

For handling the odd and even length edge condition-- If Linked list is odd, for sure fast's next would be null, generating error if we tried to move it. In case of even length, it would reach null. Image

I am ready from my side, if you reply then I can start right away. Thanks

manya-aa avatar Oct 07 '25 20:10 manya-aa

I would like to work on this issue and submit a PR.

Chintha-vardhan avatar Oct 11 '25 17:10 Chintha-vardhan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!

github-actions[bot] avatar Nov 11 '25 00:11 github-actions[bot]