https://github.com/marselester/binary-search-tree
Binary Search Tree implemented using recursions.
https://github.com/marselester/binary-search-tree
Last synced: about 1 month ago
JSON representation
Binary Search Tree implemented using recursions.
- Host: GitHub
- URL: https://github.com/marselester/binary-search-tree
- Owner: marselester
- Created: 2018-08-18T08:24:13.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-27T12:15:57.000Z (over 6 years ago)
- Last Synced: 2024-06-20T09:21:51.344Z (11 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Binary Search Tree
[](https://godoc.org/github.com/marselester/binary-search-tree)
[](https://goreportcard.com/report/github.com/marselester/binary-search-tree)Binary Search Tree (BST) is a tree structure where key in a node is larger than the keys in all its **left** children
and smaller than the keys in **right** children. New nodes are attached at the bottom of the tree.BST can provide fast search/inserts, and you can get all the keys in order:
1. get all left children (smaller)
2. get the current key
3. get all right children (larger).Those properties can be leveraged in [HastyDB](https://github.com/marselester/hastydb) to implement a memtable,
though in practise it's better to use a self-balancing tree such as Red-Black tree.The running time depends on the shape of a tree which depends on the order in which keys were inserted.
Lg N is the best case (tree is balanced), e.g., when keys inserted in a random order, so there are no long paths.
N in the worst case (N nodes in a search path). The worst case scenario happens when keys are inserted in a sorted order.## Usage Example
```go
package mainimport (
"fmt""github.com/marselester/binary-search-tree"
)func main() {
tree := bst.Tree{}
tree.Set("name", []byte("Bob"))
fmt.Printf("%s", tree.Get("name"))
}
```