{"id":23464623,"url":"https://github.com/filip-kustura/graph-cycle-detection","last_synced_at":"2025-04-12T15:24:44.483Z","repository":{"id":180083809,"uuid":"552879847","full_name":"filip-kustura/graph-cycle-detection","owner":"filip-kustura","description":"Solution to a graph theory problem meeting a specific time complexity constraint. Developed in C++ using the breadth-first search algorithm. Created in December 2021 as part of the Design and Analysis of Algorithms course, with a presentation delivered in January 2022.","archived":false,"fork":false,"pushed_at":"2024-12-14T21:24:44.000Z","size":110,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T02:42:26.711Z","etag":null,"topics":["algorithms","bfs","breadth-first-search","c-plus-plus","coding-assignment","cpp","cycle-detection","data-structures","graph-algorithms","graph-theory","graph-traversal","time-complexity","time-complexity-analysis","undirected-graphs"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/filip-kustura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-10-17T11:23:01.000Z","updated_at":"2024-12-14T21:32:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"38b7a664-96b7-4802-a8f0-3c60a8aaa5d6","html_url":"https://github.com/filip-kustura/graph-cycle-detection","commit_stats":null,"previous_names":["fikustura/cpp-teorija-grafova","filip-kustura/cpp-teorija-grafova"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filip-kustura%2Fgraph-cycle-detection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filip-kustura%2Fgraph-cycle-detection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filip-kustura%2Fgraph-cycle-detection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/filip-kustura%2Fgraph-cycle-detection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/filip-kustura","download_url":"https://codeload.github.com/filip-kustura/graph-cycle-detection/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248587598,"owners_count":21129262,"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":["algorithms","bfs","breadth-first-search","c-plus-plus","coding-assignment","cpp","cycle-detection","data-structures","graph-algorithms","graph-theory","graph-traversal","time-complexity","time-complexity-analysis","undirected-graphs"],"created_at":"2024-12-24T10:50:31.559Z","updated_at":"2025-04-12T15:24:44.461Z","avatar_url":"https://github.com/filip-kustura.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Graph Cycle Detection\r\n\r\nThis repository contains a C++ implementation for solving the following problem:\r\n\r\n**Problem Statement:**\r\nGiven a connected undirected graph and a specific edge \\(e\\), determine whether \\(e\\) is part of a cycle. The solution has a time complexity of \\(O(m + n)\\), where \\(m\\) is the number of edges and \\(n\\) is the number of vertices in the graph.\r\n\r\n## Approach\r\nThe solution involves the following steps:\r\n\r\n1. **Remove the Edge**:\r\n   Remove the given edge \\(e\\) (connecting vertices \\(v\\) and \\(w\\)) from the graph.\r\n\r\n2. **Breadth-First Search (BFS):**\r\n   Start BFS from one of the vertices of the edge (e.g., \\(v\\)). Check if there exists a path to the other vertex \\(w\\). If such a path exists, then the edge \\(e\\) is part of a cycle; otherwise, it is not.\r\n\r\n   BFS is implemented using a queue to store open vertices and a visited array to mark visited vertices. The time complexity is achieved as described in the book *Introduction to Algorithms* by Cormen et al.\r\n\r\n## Files\r\nThe implementation is split into three files for clarity and modularity:\r\n\r\n- **`graph.h`**: Interface for the graph data structure.\r\n- **`graph.cpp`**: Implementation of the graph interface.\r\n- **`main.cpp`**: Client program for loading a graph, parsing input, and determining if an edge is part of a cycle.\r\n\r\nAdditionally, a PowerPoint presentation explaining the solution is included.\r\n\r\n## Input Format\r\nGraphs are read from a `data.txt` file with the following format:\r\n\r\n- The first line contains an integer \\(V\\), representing the number of vertices in the graph. Vertices are indexed from 0 to \\(V-1\\).\r\n- Each subsequent line contains two integers, separated by a space, representing an edge between two vertices.\r\n\r\n### Example `data.txt` File\r\n```\r\n5\r\n0 1\r\n1 2\r\n2 3\r\n3 4\r\n4 0\r\n```\r\n\r\n## Compilation\r\nCompile the program using the following command:\r\n\r\n```bash\r\ng++ -o cycle_detection main.cpp graph.cpp\r\n```\r\n\r\n## Running the Program\r\nProvide the edge to be checked as a command-line argument:\r\n\r\n```bash\r\n./cycle_detection edge_start edge_end\r\n```\r\n\r\n### Example\r\nTo check if the edge `(0, 1)` is part of a cycle:\r\n\r\n```bash\r\n./cycle_detection 0 1\r\n```\r\n\r\n## Notes\r\n- The file `data.txt` must not contain duplicate edges. This limitation is not explicitly handled in the current implementation.\r\n- An alternative, direct way of initializing the graph (via hardcoding) is available in `main.cpp`, but it is commented out for simplicity.\r\n\r\n## Testing\r\nTo test the program:\r\n1. Prepare a `data.txt` file in the specified format.\r\n2. Compile and run the program with various edge inputs to observe the results.\r\n\r\n---\r\n\r\nFeel free to explore the implementation and provide feedback or suggestions.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilip-kustura%2Fgraph-cycle-detection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffilip-kustura%2Fgraph-cycle-detection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffilip-kustura%2Fgraph-cycle-detection/lists"}