{"id":21548702,"url":"https://github.com/nikeee/poor-mans-floyd","last_synced_at":"2025-03-18T02:17:12.454Z","repository":{"id":69058066,"uuid":"254502337","full_name":"nikeee/poor-mans-floyd","owner":"nikeee","description":null,"archived":false,"fork":false,"pushed_at":"2020-04-11T17:38:21.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-24T09:29:36.576Z","etag":null,"topics":["cycle-detection","floyd","floyd-cycle-detection","graph","profiling"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikeee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-09T23:49:38.000Z","updated_at":"2020-04-11T17:38:23.000Z","dependencies_parsed_at":"2023-02-21T12:30:14.013Z","dependency_job_id":null,"html_url":"https://github.com/nikeee/poor-mans-floyd","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikeee%2Fpoor-mans-floyd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikeee%2Fpoor-mans-floyd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikeee%2Fpoor-mans-floyd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikeee%2Fpoor-mans-floyd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikeee","download_url":"https://codeload.github.com/nikeee/poor-mans-floyd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244141482,"owners_count":20404837,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cycle-detection","floyd","floyd-cycle-detection","graph","profiling"],"created_at":"2024-11-24T06:19:26.867Z","updated_at":"2025-03-18T02:17:12.447Z","avatar_url":"https://github.com/nikeee.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Poor Man's Floyd\n\nFloyd's algorithm implemented for an array as well as a directed graph where every node has a maximum of one successor (or simple: a linked list that might have a cycle).\n\nSeen in this video: https://www.youtube.com/watch?v=pKO9UjSeLew\n\nWhile I was browsing GitHub, I found [this repository](https://github.com/maciej-nowak/ITS-Floyd-Cycle-Detection). It uses floyd's cycle detection to find hash collisions. It might be interesting as further reading and practical application of this algorithm.\n\n## Benchmarking Result\n\n### Memory Usage\n```shell\n$ pipenv install\n$ pipenv shell\n\n$ python3 -m memory_profiler profile.py\n```\n\nResults on my machine (Windows 10, running python3 in legacy WSL, i5-3570, 16GB RAM)\n```\nFilename: profile.py\n\nLine #    Mem usage    Increment   Line Contents\n================================================\n     9    400.0 MiB    400.0 MiB   @profile\n    10                             def main():\n    11    401.2 MiB      1.2 MiB       find_cycle_sort(data)\n    12    402.6 MiB      1.4 MiB       find_cycle_set(data)\n    13    402.6 MiB      0.0 MiB       find_cycle_floyd(data)\n```\n\n### Wallclock Time\n```shell\n$ python3 main_array.py\n```\nResults on my machine (same setup as above):\n```\nfind_cycle_sort(data):  95.93714189999992s\nfind_cycle_set(data):   0.2260710000000472s\nfind_cycle_floyd(data): 0.7033440999998675s\n```\n\n### Conclusion\nAlthough `find_cycle_set` and `find_cycle_floyd` have the same time complexity on paper, it depends on the input. floyd genereally seemed a bit slower than the naive `set` implementation. On large inputs however, floyd used a lot less memory compared to the other two methods.\nFloyd uses only two pointers whereas the set implementation uses a set (of size up to `n`) and the sort implementation an array (of size exactly `n`).\n\nTake this with a grain of salt as the profiling was done without deep knowledge on how to measure these things properly. Also, it was done inside Legacy WSL which leads to pretty poor performance in general.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikeee%2Fpoor-mans-floyd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikeee%2Fpoor-mans-floyd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikeee%2Fpoor-mans-floyd/lists"}