{"id":20409674,"url":"https://github.com/sleekpanther/reverse-delete-algorithm","last_synced_at":"2025-03-05T02:43:02.577Z","repository":{"id":115108653,"uuid":"99710334","full_name":"SleekPanther/reverse-delete-algorithm","owner":"SleekPanther","description":"Greedy Algorithm to find a minimum spanning tree in an undirected graph by deleting heaviest edges unless it would disconnect the graph","archived":false,"fork":false,"pushed_at":"2017-08-09T12:14:23.000Z","size":126,"stargazers_count":1,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-15T13:08:05.675Z","etag":null,"topics":["algorithm","algorithm-design","algorithms","edge","graph","greedy","greedy-algorithms","minimum-spanning-tree","minimum-spanning-trees","mst","noah","noah-patullo","noahpatullo","pattullo","pattulo","patullo","patulo","reverse-delete","reverse-delete-algorithm","tree"],"latest_commit_sha":null,"homepage":"","language":"Java","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/SleekPanther.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":"2017-08-08T15:52:36.000Z","updated_at":"2024-04-09T15:51:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"7468a79c-6303-4cbc-a936-895ad2eb6016","html_url":"https://github.com/SleekPanther/reverse-delete-algorithm","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/SleekPanther%2Freverse-delete-algorithm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Freverse-delete-algorithm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Freverse-delete-algorithm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SleekPanther%2Freverse-delete-algorithm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SleekPanther","download_url":"https://codeload.github.com/SleekPanther/reverse-delete-algorithm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241955039,"owners_count":20048405,"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":["algorithm","algorithm-design","algorithms","edge","graph","greedy","greedy-algorithms","minimum-spanning-tree","minimum-spanning-trees","mst","noah","noah-patullo","noahpatullo","pattullo","pattulo","patullo","patulo","reverse-delete","reverse-delete-algorithm","tree"],"created_at":"2024-11-15T05:42:54.377Z","updated_at":"2025-03-05T02:43:02.570Z","avatar_url":"https://github.com/SleekPanther.png","language":"Java","readme":"# Reverse Delete Algorithm (Minimum Spanning Tree)\nGreedy Algorithm to find a minimum spanning tree in an undirected graph by deleting heaviest edges unless it would disconnect the graph\n\n## Problem Statement\n**Minim Spanning Tree:** a subset of nodes that touches all vertices while keeping all nodes connected and uses the sum of the edge weights in a minimum  \nA Minimum spanning tree yields a graph with **M-1** edges because adding 1 more edge would by definition create a cycle\n\n### Graph\n![](images/graph.png)\n\n### Minimum Spanning Tree\n![](images/mst.png)  \n#### Weight = 18+14+9+7+6+5+2 = 61\n\n## Reverse Delete Greedy Strategy\n**Start with all edges in the tree T. Consider edges in descending order of weight. Delete edge from T unless doing so would disconnect T**\n\n- Sort edges by weight\n- Initialize MST with all edges\n- Delete the highest weight edge\n  - If deleting the edge disconnects the graph, add it back\n  - Otherwise continue\n\n## Usage\n- Node names are consecutive integers starting from `0`\n- Create a graph: `ArrayList\u003cEdge\u003e graph = new ArrayList\u003cEdge\u003e();`\n- Graph undirected edge list, but **only add each edge once**\n  - In the graph there is an edge from `0` to `9` with weight=`9`\n  - This bidirectional edge can just be represented once: `graph.add(new Edge(0, 1, 9));`\n- Count the vertices in the graph: `int vertexCount = 8;`\n- Call the static method `ReverseDeleteMST.findMST(graph, vertexCount);`\n\n# Code Notes\n- Due to the implementation of Breadth First Search, the code creates an additional copy of the graph as an adjacency list\n- This adjacency list graph is the one where edges are deleted, the original input graph as an edge list is left in tact\n- The MST is technically built up from nothing and added to if deleting an edge in the adjacency list would disconnect the graph\n\n## References\n- [Kevin Wayne Slides](https://www.cs.princeton.edu/~wayne/kleinberg-tardos/pdf/04GreedyAlgorithmsII.pdf#page=14)\n- [University of Illinois - Minimum Spanning Trees](https://courses.engr.illinois.edu/cs473/sp2011/Lectures/12_notes.pdf)\n- [T. M. Murali Slides](http://courses.cs.vt.edu/cs5114/spring2009/lectures/lecture05-greedy-graph-algorithms.pdf#page=36)\n- [Fan Chung Graham Slides](http://www.math.ucsd.edu/~fan/teach/202/14/04mst.pdf#page=11)\n- [Reverse Delete Algorithm - GeeksForGeeks](http://www.geeksforgeeks.org/reverse-delete-algorithm-minimum-spanning-tree/) Algorithm strategy, code only briefly referenced\n- [Remove items from ArrayList with certain value - Stack Overflow](https://stackoverflow.com/a/29107463/8132253) Lambda expression to delete specific value from `ArrayList`\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsleekpanther%2Freverse-delete-algorithm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsleekpanther%2Freverse-delete-algorithm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsleekpanther%2Freverse-delete-algorithm/lists"}