{"id":22513462,"url":"https://github.com/emahtab/topological-sort-problems","last_synced_at":"2026-03-19T23:02:41.242Z","repository":{"id":259815849,"uuid":"879491895","full_name":"eMahtab/topological-sort-problems","owner":"eMahtab","description":"Topological Sort Problems","archived":false,"fork":false,"pushed_at":"2024-10-28T02:41:32.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T03:19:28.210Z","etag":null,"topics":["kahns-alogrithm","leetcode","topological-sort"],"latest_commit_sha":null,"homepage":"","language":null,"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/eMahtab.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":"2024-10-28T02:25:11.000Z","updated_at":"2024-10-28T13:25:52.000Z","dependencies_parsed_at":"2024-10-28T15:25:00.515Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/topological-sort-problems","commit_stats":null,"previous_names":["emahtab/topological-sort-problems"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftopological-sort-problems","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftopological-sort-problems/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftopological-sort-problems/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Ftopological-sort-problems/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/topological-sort-problems/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245950667,"owners_count":20699107,"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":["kahns-alogrithm","leetcode","topological-sort"],"created_at":"2024-12-07T03:12:25.199Z","updated_at":"2026-01-07T07:17:30.957Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Topological Sort Problems : O(V+E)\n\nTopological sort of a directed graph is a linear ordering of its vertices such that for every directed edge (u,v) from vertex u to vertex v, u comes before v in the ordering.\n\nWhen topological sort is implemented using **Kahn's Algorithm (BFS with a queue)**, the time complexity and space complexity are as follows:\n\n### Time Complexity : O(V+E)\n##### Explanation:\n1. Counting in-degrees takes 𝑂(𝐸) time because we iterate over each edge once.\n2. Enqueueing and dequeueing each vertex takes 𝑂(𝑉) time.\n3. Processing each neighbor of each vertex (decreasing in-degrees and enqueuing zero in-degree nodes) takes 𝑂(𝐸) time as each edge is visited once.\n\n### Space Complexity : : O(V+E)\n##### Explanation:\nThe space complexity is also 𝑂(𝑉+𝐸) because:\n1. We need space to store the graph (using an adjacency list) with 𝑉 vertices and 𝐸 edges, which takes 𝑂(𝑉+𝐸).\n2. We maintain an in-degree array of size 𝑉, taking 𝑂(𝑉).\n3. The queue holds vertices with zero in-degrees, and in the worst case, all vertices could be added to the queue, so it also takes 𝑂(𝑉) space.\n\n\n## Problems :\n1. https://leetcode.com/problems/course-schedule\n2. https://leetcode.com/problems/course-schedule-ii\n3. https://leetcode.com/problems/parallel-courses\n4. https://leetcode.com/problems/find-all-possible-recipes-from-given-supplies\n5. https://leetcode.com/problems/alien-dictionary\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ftopological-sort-problems","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Ftopological-sort-problems","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Ftopological-sort-problems/lists"}