{"id":25171753,"url":"https://github.com/basemax/bstgo","last_synced_at":"2025-06-12T03:10:07.801Z","repository":{"id":151535234,"uuid":"582310521","full_name":"BaseMax/BSTGo","owner":"BaseMax","description":"This is a Go implementation of the BST data structure with a few of the most common operations. The algorithms code should be easy to understand. BST Tree is a binary tree in which the value of each node is greater than or equal to any value stored in the left sub-tree, and less than or equal to any value stored in the right sub-tree.","archived":false,"fork":false,"pushed_at":"2022-12-26T20:00:25.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-09T22:46:52.094Z","etag":null,"topics":["algorithm","algorithms","algorithms-and-data-structures","bst","data-structure","datastructure","go","golang","tere-data-structure","tree","tree-algorithm","tree-algorithms","tree-datastructure","tree-insert","tree-search","tree-structure"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BaseMax.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-12-26T12:20:25.000Z","updated_at":"2022-12-27T10:45:26.000Z","dependencies_parsed_at":"2023-07-10T14:00:42.099Z","dependency_job_id":null,"html_url":"https://github.com/BaseMax/BSTGo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BaseMax/BSTGo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2FBSTGo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2FBSTGo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2FBSTGo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2FBSTGo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BaseMax","download_url":"https://codeload.github.com/BaseMax/BSTGo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BaseMax%2FBSTGo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259388091,"owners_count":22849755,"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","algorithms","algorithms-and-data-structures","bst","data-structure","datastructure","go","golang","tere-data-structure","tree","tree-algorithm","tree-algorithms","tree-datastructure","tree-insert","tree-search","tree-structure"],"created_at":"2025-02-09T09:21:58.631Z","updated_at":"2025-06-12T03:10:07.796Z","avatar_url":"https://github.com/BaseMax.png","language":"Go","readme":"# BST Go\r\n\r\nThis is a Go implementation of the BST data structure with a few of the most common operations. The algorithms code should be easy to understand. BST Tree is a binary tree in which the value of each node is greater than or equal to any value stored in the left sub-tree, and less than or equal to any value stored in the right sub-tree.\r\n\r\n## Structure\r\n\r\n**Types:**\r\n\r\n```go\r\ntype Node struct {\r\n\tvalue int\r\n\tleft  *Node\r\n\tright *Node\r\n}\r\n\r\ntype BST struct {\r\n\troot *Node\r\n}\r\n```\r\n\r\n**Functions:**\r\n\r\n- `func insert(root *Node, value int) *Node`: Insert a new node into the BST.\r\n- `func insertNonRecursively(root *Node, value int) *Node`: Insert a new node into the BST (non-recursively).\r\n- `func find(root *Node, value int) *Node`: Find the node with the given value.\r\n- `func findNonRecursively(root *Node, value int) *Node`: Find the node with the given value (non-recursively).\r\n- `func findLeftMost(root *Node) *Node`: Find the left most child of the given node.\r\n- `func findParent(root *Node, value int) *Node: Find the parent of the given node.\r\n- `func findFirstParent(root *Node) *Node`: Find the first parent of the given node which is the left child of its parent.\r\n- `func findNext(root *Node, value int) *Node`: Find next of the given node.\r\n- `func findNextAny(root *Node, node *Node) *Node`: Find next of the given node (for any Binary Tree).\r\n- `func deleteNode(root *Node, value int) *Node`: Delete a node with the given value.\r\n- `func deleteNodeNonRecursively(root *Node, value int) *Node`: Delete a node with the given value (non-recursive).\r\n- `func getHeight(root *Node) int`: Get the height of the BST.\r\n- `func getHeightNonRecursive(root *Node) int`: Get the height of the BST (non-recursively).\r\n- `func max(a, b int) int`: Get the maximum of two integers.\r\n- `func getSize(root *Node) int`: Get the size of the BST.\r\n- `func getSizeNonRecursive(root *Node) int`: Get the size of the BST (non-recursively).\r\n\r\n## Example\r\n\r\n```go\r\n// Create a BST\r\nbst := BST{}\r\n\r\n// Insert nodes into the BST\r\nbst.root = insert(bst.root, 5)\r\nbst.root = insert(bst.root, 3)\r\nbst.root = insert(bst.root, 7)\r\nbst.root = insert(bst.root, 2)\r\nbst.root = insert(bst.root, 4)\r\nbst.root = insert(bst.root, 6)\r\nbst.root = insert(bst.root, 8)\r\n\r\n// insertNonRecursively\r\nbst.root = insertNonRecursively(bst.root, 15)\r\nbst.root = insertNonRecursively(bst.root, 13)\r\nbst.root = insertNonRecursively(bst.root, 17)\r\nbst.root = insertNonRecursively(bst.root, 12)\r\nbst.root = insertNonRecursively(bst.root, 14)\r\n\r\n// Find the node with the given value\r\nn := findNext(bst.root, 5)\r\nif n != nil {\r\n    println(n.value)\r\n}\r\n\r\n// Find a node\r\nn = find(bst.root, 5)\r\nif n != nil {\r\n    println(n.value)\r\n}\r\n\r\n// findNonRecursively\r\nn = findNonRecursively(bst.root, 5)\r\nif n != nil {\r\n    println(n.value)\r\n}\r\n\r\n// Get the height\r\nprintln(getHeight(bst.root))\r\n```\r\n\r\nCopyright (c) 2022, Max Base\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasemax%2Fbstgo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasemax%2Fbstgo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasemax%2Fbstgo/lists"}