{"id":27289249,"url":"https://github.com/mgduda/dag-problem","last_synced_at":"2026-07-15T20:32:46.649Z","repository":{"id":211017236,"uuid":"727926137","full_name":"mgduda/dag-problem","owner":"mgduda","description":"An exercise in detecting cycles in directed graphs","archived":false,"fork":false,"pushed_at":"2023-12-13T00:40:15.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-11T21:13:51.662Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mgduda.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}},"created_at":"2023-12-05T21:29:51.000Z","updated_at":"2023-12-12T20:29:21.000Z","dependencies_parsed_at":"2023-12-12T21:32:39.368Z","dependency_job_id":null,"html_url":"https://github.com/mgduda/dag-problem","commit_stats":null,"previous_names":["mgduda/dag-problem"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2Fdag-problem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2Fdag-problem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2Fdag-problem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2Fdag-problem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgduda","download_url":"https://codeload.github.com/mgduda/dag-problem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480427,"owners_count":21110937,"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":[],"created_at":"2025-04-11T21:13:53.912Z","updated_at":"2025-10-16T12:59:14.854Z","avatar_url":"https://github.com/mgduda.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dag-problem\nAn exercise in detecting cycles in digraphs\n\n-----\n\nLet $G = (V,E)$ be a directed graph (*digraph*) with vertex set $V$ and edge set $E$. Each\ndirected edge $e \\in E$ is an ordered pair of vertices $(v_1,v_2)$, with $v_1, v_2 \\in V$. Note that a\ndirected edge from a vertex $v_i$ to itself, i.e., an edge $(v_i,v_i)$, is permissible. Fig. 1 shows\na simple directed graph with $V = \\lbrace 0, 1, 2, 3 \\rbrace$ and $E = \\lbrace (0,1), (0,3), (1,3), (3,2), (2,0) \\rbrace$.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"/figures/digraph.svg\"/\u003e\n\u003cbr\u003e\n\u003cem\u003eFig. 1: A simple directed graph.\u003c/em\u003e\n\u003c/p\u003e\n\nA directed path is a sequence of vertices $\\langle v_0, \\ldots, v_m \\rangle$ such that\n$(v_i, v_{i+1}) \\in E$ for $i = 0, \\ldots, m-1$. A cycle in a digraph is a path with $v_0 \\equiv v_m$.\nThe digraph in Fig. 1 contains two cycles: $\\langle 0, 1, 3, 2, 0 \\rangle$ and $\\langle 3, 2, 0, 3 \\rangle$.\nA directed acyclic graph (*dag*) is a digraph that contains no cycles. Fig. 2 shows a simple\ndag; note that the edge $(0,2)$ replaces the edge $(2,0)$ from the digraph in Fig. 1.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"/figures/dag.svg\"/\u003e\n\u003cbr\u003e\n\u003cem\u003eFig. 2: A simple dag.\u003c/em\u003e\n\u003c/p\u003e\n\nA digraph $G = (V,E)$ may be respresented as a set of adjacency\nlists, one list for each vertex $v \\in V$. The adjacency list for $v$ contains the vertices\n$u_i$ for all $(v,u_i) \\in E$, i.e, all vertices to which $v$ contains an outgoing edge.\nThe adjacency list for vertex $0$ in Fig. 1 contains the vertices $1$ and $3$.\n\nIf we assume that the vertices are numbered $0, \\ldots, |V|-1$, then the adjacency list\nfor each vertex $v_i$ may be represented as a bit-array, where a bit value of 1 in\narray position $j$ implies an edge $(v_i, v_j)$. When $|V| \\le 32$, a 32-bit integer\nis sufficient to represent the adjacency list for a vertex. Fig. 3 shows a bit-array\nrepresentation of the adjacency list for vertex $0$ of the digraph in Fig. 1.\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"/figures/adj_list.svg\"/\u003e\n\u003cbr\u003e\n\u003cem\u003eFig. 3: A bit-array representation of an adjacency list.\u003c/em\u003e\n\u003c/p\u003e\n\nIn this exercise, our objective is to write a function in C/C++ that will\ndetermine whether a digraph is a dag. The main driver program, which is\nprovided in the file `main.c`, takes as a command-line argument the name of a file containing a\nrepresentation of a digraph and reads the graph into an array of `uint32_t`\nvalues. The size of the array is equal to the number of vertices in the digraph,\nand each element $i$ of the array stores the adjacency list for vertex $v_i$.\n\nThe function to determine whether a digraph is a dag has the following\nprototype:\n```c\nint is_dag(uint32_t digraph[], int n_vertices);\n```\nThis function takes as input an adjacency list representation of a digraph\nand the number of vertices in the graph. The size of the `digraph` array is\n`n_vertices`, with `n_vertices` at most 32. The function returns 1 if the given\ngraph is a dag and 0 otherwise.\n\nAfter implementing the `is_dag` function, the program should be run for each of\nthe digraphs in the `test_graphs/` sub-directory of this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgduda%2Fdag-problem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgduda%2Fdag-problem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgduda%2Fdag-problem/lists"}