go-ds
所属分类:数据结构
开发工具:GO
文件大小:0KB
下载次数:0
上传日期:2024-03-05 09:44:54
上 传 者:
sh-1993
说明: 竞争性编程的Go数据结构
(Go data structures for competitive programming)
文件列表:
tree/
LICENSE
go.mod
go.sum
# Go Data Structures
## Tree
```sh
go get github.com/adrian-lin-1-0-0/go-ds/tree@latest
```
- [Fenwick tree (Binary Index Tree)](https://github.com/adrian-lin-1-0-0/go-ds/blob/master/./tree/bit.go)
Time Complexity
| Operation | Average | Worst case |
| ---- | ---- | --- |
| Update | O(log n) | O(log n) |
| Query | O(log n) | O(log n) |
| Range Query | O(log n) | O(log n) |
Space Complexity
| Average | Worst case |
| ---- | --- |
| O(n) | O(n) |
```go
package main
import (
"github.com/adrian-lin-1-0-0/go-ds/tree"
)
func main(){
bit := tree.NewBIT[int](https://github.com/adrian-lin-1-0-0/go-ds/blob/master/10)
bit.Update(1, 1)
bit.Update(2, 2)
bit.Update(3, 3)
bit.Query(3) // 6
bit.RangeQuery(1,2) // 3
}
```
近期下载者:
相关文件:
收藏者: