Add "Find Middle of a Singly Linked List" Algorithm and Tests
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
I would like to work on this enhancement issue.
kindly assign this issue to me
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.
I am curious to solve this , Can i work on this..?
I want to contribute to this part of the project.
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.
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.
I am ready from my side, if you reply then I can start right away. Thanks
I would like to work on this issue and submit a PR.
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!