{"id":21408712,"url":"https://github.com/vomnes/algorithms-go","last_synced_at":"2025-06-24T10:34:24.810Z","repository":{"id":68249955,"uuid":"235435702","full_name":"vomnes/algorithms-go","owner":"vomnes","description":"Algorithms and data structures implementation in Go","archived":false,"fork":false,"pushed_at":"2020-02-07T20:27:41.000Z","size":526,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-05T07:04:15.531Z","etag":null,"topics":["a-star-algorithm","bfs-algorithm","binary-search","bubble-sort","dfs-algorithm","go","graph-algorithms","heap","heap-sort","queue","quicksort","stack","trie-data-structure"],"latest_commit_sha":null,"homepage":"","language":"Go","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/vomnes.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}},"created_at":"2020-01-21T20:30:55.000Z","updated_at":"2025-01-08T11:24:17.000Z","dependencies_parsed_at":"2023-02-27T15:16:04.723Z","dependency_job_id":null,"html_url":"https://github.com/vomnes/algorithms-go","commit_stats":null,"previous_names":["vomnes/graph-algorithms-go"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vomnes%2Falgorithms-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vomnes%2Falgorithms-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vomnes%2Falgorithms-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vomnes%2Falgorithms-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vomnes","download_url":"https://codeload.github.com/vomnes/algorithms-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243905503,"owners_count":20366835,"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":["a-star-algorithm","bfs-algorithm","binary-search","bubble-sort","dfs-algorithm","go","graph-algorithms","heap","heap-sort","queue","quicksort","stack","trie-data-structure"],"created_at":"2024-11-22T17:18:03.280Z","updated_at":"2025-03-16T17:29:37.870Z","avatar_url":"https://github.com/vomnes.png","language":"Go","readme":"# Algorithms\nAlgorithms implementation in Golang\n\n### Data Structures\n- Queue\n- Stack\n- Heap\n- Trie\n\n### Algorithms\n- BFS\n- DBS\n- A*\n- Max XOR\n- Binary Search\n- Bubble Sort\n- Heap Sort\n- Quicksort\n\n## Sort Benchmark\n\u003cimg alt=\"Sort benchmark\" src=\"./img/SortBenchmark.png\" title=\"sort-benchmark\" width=\"75%\"\u003e\n\n## Maximum Xor - Trie Data Structure\n\u003cimg alt=\"Maximum Xor\" src=\"./img/MaxXor.jpg\" title=\"maximum-xor\"\u003e\n\n## Manage Map\nManage map contains a program that read a file map that represent a maze to create a graph :  \n- _'.'_ is a path\n- _'#'_ is a wall\n- _'S'_ is the starting point\n- _'E'_ is the ending point\n\n### Exploration map example\nThe map exploration is type BFS.  \n\u003cimg alt=\"program running\" src=\"./img/ExploreMaze.gif\" title=\"program-running\"\u003e\n\n## Breadth-first Search\nBreadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root, and explores all of **the neighbor nodes** at the present depth **prior to moving on to the nodes at the next depth level**. (_Source Wikipedia_)\n\n### Pseudocode\n```\n1  procedure BFS(G, start_v) is\n2      let Q be a queue\n3      label start_v as discovered\n4      Q.enqueue(start_v)\n5      while Q is not empty do\n6          v := Q.dequeue()\n7          if v is the goal then\n8              return v\n9          for all edges from v to w in G.adjacentEdges(v) do\n10             if w is not labeled as discovered then\n11                 label w as discovered\n12                 w.parent := v\n13                 Q.enqueue(w)\n```\n\n## Depth-first Search\nDepth-first search (DFS) is an algorithm for traversing or searching tree or graph data structures. The algorithm starts at the root node and **explores as far as possible along each branch** before backtracking. (_Source Wikipedia_)\n\n### Pseudocode\n```\n1  procedure DFS-iterative(G, v) is\n2      let S be a stack\n3      S.push(v)\n4      while S is not empty do\n5          v = S.pop()\n6          if v is not labeled as discovered then\n7              label v as discovered\n8              for all edges from v to w in G.adjacentEdges(v) do\n9                  S.push(w)\n```\n\n## A* Search Algorithm\nA* (pronounced \"A-star\") is a graph traversal and path search algorithm, which is often used in computer science due to its completeness, optimality, and optimal efficiency. In practical travel-routing systems, it is generally outperformed by algorithms which can pre-process the graph to attain better performance, as well as memory-bounded approaches; however, A* is still the best solution in many cases.\n\nAt each iteration of its main loop, **A Star needs to determine which of its paths to extend**. It does so based **on the cost of the path and an estimate of the cost required to extend the path all the way to the goal**.  \nSpecifically, A* selects the path that minimizes :  \n\n\u003e f(n) = g(n) + h(n)\n\n- *g(n)* is the cost of the path from the start node to n  \n- *h(n)* is a heuristic function that estimates the cost of the cheapest path from n to the goal for example using a [Euclidean distance](https://en.wikipedia.org/wiki/Euclidean_distance) formula  \n\n(_Source Wikipedia_)\n\n### Pseudocode\n```\nfunction reconstruct_path(cameFrom, current)\n    total_path := {current}\n    while current in cameFrom.Keys:\n        total_path.prepend(current)\n        current := cameFrom[current]\n    return total_path\n\n// A* finds a path from start to goal.\n// h is the heuristic function. h(n) estimates the cost to reach goal from node n.\nfunction A_Star(start, goal, h)\n    // The set of discovered nodes that may need to be (re-)expanded.\n    // Initially, only the start node is known.\n    openSet := {start}\n\n    // For node n, cameFrom[n] is the node immediately preceding it on the cheapest path from start to n currently known.\n    cameFrom := an empty map\n\n    // For node n, gScore[n] is the cost of the cheapest path from start to n currently known.\n    gScore := map with default value of Infinity\n    gScore[start] := 0\n\n    // For node n, fScore[n] := gScore[n] + h(n).\n    fScore := map with default value of Infinity\n    fScore[start] := h(start)\n\n    while openSet is not empty\n        current := the node in openSet having the lowest fScore[] value\n        if current = goal\n            return reconstruct_path(cameFrom, current)\n\n        openSet.Remove(current)\n        for each neighbor of current\n            // d(current,neighbor) is the weight of the edge from current to neighbor\n            // tentative_gScore is the distance from start to the neighbor through current\n            tentative_gScore := gScore[current] + d(current, neighbor)\n            if tentative_gScore \u003c gScore[neighbor]\n                // This path to neighbor is better than any previous one. Record it!\n                cameFrom[neighbor] := current\n                gScore[neighbor] := tentative_gScore\n                fScore[neighbor] := gScore[neighbor] + h(neighbor)\n                if neighbor not in openSet\n                    openSet.add(neighbor)\n\n    // Open set is empty but goal was never reached\n    return failure\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvomnes%2Falgorithms-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvomnes%2Falgorithms-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvomnes%2Falgorithms-go/lists"}