{"id":20538808,"url":"https://github.com/aswinkarthik/algorithms-in-go","last_synced_at":"2025-09-21T00:19:43.273Z","repository":{"id":76158241,"uuid":"107589129","full_name":"aswinkarthik/algorithms-in-go","owner":"aswinkarthik","description":"Implementations of various algorithms in golang","archived":false,"fork":false,"pushed_at":"2019-09-04T04:43:24.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-08-08T04:11:26.558Z","etag":null,"topics":["algorithms","algorithms-implemented","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aswinkarthik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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-10-19T19:26:44.000Z","updated_at":"2024-06-19T11:07:57.853Z","dependencies_parsed_at":null,"dependency_job_id":"3e28783d-dec3-44aa-b9ad-87788b9ffaec","html_url":"https://github.com/aswinkarthik/algorithms-in-go","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswinkarthik%2Falgorithms-in-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswinkarthik%2Falgorithms-in-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswinkarthik%2Falgorithms-in-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aswinkarthik%2Falgorithms-in-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aswinkarthik","download_url":"https://codeload.github.com/aswinkarthik/algorithms-in-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242144497,"owners_count":20078966,"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","algorithms-implemented","golang"],"created_at":"2024-11-16T00:47:53.616Z","updated_at":"2025-09-21T00:19:38.208Z","avatar_url":"https://github.com/aswinkarthik.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Algorithms in Go\n\n[![Build Status](https://travis-ci.org/aswinkarthik/algorithms-in-go.svg?branch=master)](https://travis-ci.org/aswinkarthik/algorithms-in-go)\n\nThis repository is to implement various data structures and alogrithms in Go.\n\n## Datastructures\n\n- [Stack](https://godoc.org/github.com/aswinkarthik/algorithms-in-go/stack)\n- [Queue](https://godoc.org/github.com/aswinkarthik/algorithms-in-go/queue)\n- [Heap](https://godoc.org/github.com/aswinkarthik/algorithms-in-go/heap)\n\n## Algorithms\n\n- [Rabin-Karp Substring Search](https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm)\n\n## Usage\n\n### Stack\n\n```go\nfunc main() {\n    s := stack.New()\n\n    s.Push(6)\n    s.Push(8)\n\n    top, _ := s.Pop()\n    fmt.Println(top) // Prints 8\n\n    top, _ = s.Peek()\n    fmt.Println(top) // Prints 6\n}\n```\n\nFor more docs on [stack](https://godoc.org/github.com/aswinkarthik/algorithms-in-go/stack)\n\n### Queue\n\n```go\nfunc main() {\n    q := queue.New()\n\n    q.Enqueue(6)\n    q.Enqueue(8)\n\n    first, _ := q.Dequeue()\n    fmt.Println(first) // Prints 6\n\n    first, _ = q.First()\n    fmt.Println(first) // Prints 8\n}\n```\n\nFor more docs on [queue](https://godoc.org/github.com/aswinkarthik/algorithms-in-go/queue)\n\n### Heap\n\nBy default, you could create a MinHeap or MaxHeap with int64 items\n\n```go\nfunc main() {\n    h := heap.NewMinHeapInt64()\n\n    h.Insert(int64(5))\n    h.Insert(int64(2))\n    h.Insert(int64(3))\n\n    first, _ := h.Remove()\n    fmt.Println(first) // Prints 2\n\n    second, _ := h.Remove()\n    fmt.Println(second) // Prints 3\n\n    third, _ := h.Top()\n    fmt.Println(third) // Prints 5\n}\n```\n\nYou could also create a heap of any type. You would have to define a method that asserts how your heap property should be maintained.\n\n```go\nfunc main() {\n    type myStruct struct {\n        value int\n        label string\n    }\n\n    // define how your heap property is maintained\n    comparator := func(a, b interface{}) bool {\n        return a.(myStruct).value \u003c b.(myStruct).value\n    }\n\n    first := myStruct{5, \"a\"}\n    second := myStruct{8, \"b\"}\n    third := myStruct{3, \"c\"}\n\n    h := heap.New(comparator)\n\n    h.Insert(first)\n    h.Insert(second)\n    h.Insert(third)\n\n    val, _ := h.Top()\n\n    fmt.Println(val) // Prints {3 c}\n}\n```\n\nFor more docs on [heap](https://godoc.org/github.com/aswinkarthik/algorithms-in-go/heap)\n\n## Strings\n\nMethods offered in strings package\n\n### Contains\n\nThis uses Rabin-Karp Substring match algorithm\n\n```go\nfunc main() {\n\tstrings.Contains(\"source string\", \"ce s\") // true\n}\n```\n\nFor more docs on [strings](https://godoc.org/github.com/aswinkarthik/algorithms-in-go/strings)\n\n## Test locally\n\n```bash\ngo test -v ./...\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faswinkarthik%2Falgorithms-in-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faswinkarthik%2Falgorithms-in-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faswinkarthik%2Falgorithms-in-go/lists"}