TheAlgorithms/Java

[FEATURE REQUEST] <title>Adding Hare and Tortoise Algorithm

Opened this issue · 3 comments

What would you like to Propose?

I would like to contribute Hare and Tortoise Algorithm as it is one of the most important concept when it comes to linked list

Issue details

I will add the algorithm in the linked list part

Additional Information

No response

Hello Bhumika

I am working on the issue and will be adding the Algorithm in the Linked List Section.

What would you like to propose?
I would like to propose the addition of the "Hare and Tortoise Algorithm" (also known as Floyd’s cycle detection algorithm) to the repository. This algorithm is useful for detecting cycles in a sequence, particularly in linked lists. Implementing this in Java would be a valuable addition to the existing algorithms in the repository.

Issue details
The Hare and Tortoise algorithm works by having two pointers move through the sequence at different speeds: one (the hare) moves two steps at a time, while the other (the tortoise) moves one step at a time. If there is a cycle, the two pointers will eventually meet. This algorithm is commonly used in problems involving linked lists to detect cycles efficiently, with O(n) time complexity and O(1) space complexity.

Additional Information
The proposed implementation will include both a standard use case for detecting a cycle in a linked list and a brief explanation of its time and space complexity. The code will follow Java best practices and will include comprehensive test cases to ensure functionality and correctness. This algorithm is widely recognized and often appears in technical interviews, making it a valuable resource for learners and developers.

[FEATURE REQUEST] Adding Hare and Tortoise Algorithm #5693
#5693