# pytrees


A collection of python3 implementations of trees. Including AVL Tree, Interval Tree and More.
## Install
~~~ shell
pip3 install pytrees
~~~
## Usage
~~~python
>>> from pytrees import AVLTree, IntervalTree, BinaryIndexTree, Trie
>>> avl = AVLTree.buildFromList([-1,-2,1,2,3,4,5,6])
>>> avl.visulize()
~~~
~~~ bash
-----------------Visualize Tree----------------------
2
-1 5
-2 1 3 6
4
-----------------End Visualization-------------------
~~~
~~~ python
>>> avl.delete(4)
>>> avl.visulize()
~~~
~~~ bash
-----------------Visualize Tree----------------------
2
-1 5
-2 1 3 6
-----------------End Visualization-------------------
~~~
~~~python
>>> avl.insert(0)
>>> avl.visulize()
~~~
~~~ bash
-----------------Visualize Tree----------------------
2
-1 5
-2 1 3 6
0
-----------------End Visualization-------------------
~~~
## Classes
### AVL Tree
AVL Tree.
Balanced Binary Search Tree. Gurantee for balance.
API:
- insert(self, val)
- delete(self, key)
- search(self, key)
- getDepth(self)
- preOrder(self)
- inOrder(self)
- postOrder(self)
- countNodes(self)
- buildFromList(cls, l)
### Interval Tree
Augmented data structure for checking overlaps of intervals. Gurantee for balance.
API:
- queryOverlap(self, val)
- queryAllOverlaps(self, val)
- insert(self, val)
- delete(self, key)
- search(self, key)
- getDepth(self)
- preOrder(self)
- inOrder(self)
- postOrder(self)
- countNodes(self)
- buildFromList(cls, l)
### Binary Search Tree
Simple implementation of Binary Search Tree. No gurantee for balance.
API:
- insert(self, val)
- delete(self, key)
- search(self, key)
- getDepth(self)
- preOrder(self)
- inOrder(self)
- postOrder(self)
- countNodes(self)
- buildFromList(cls, l)
### Trie (Prefix-Tree)
Prefix-tree. Useful for text search.
API:
- insert(self, word)
- search(self, word)
- startsWith(self, prefix)
- findAllWordsStartsWith(self, prefix)
- buildFromList(cls, l)
### Binary Index Tree
A Fenwick tree or Binary Indexed Tree is a data structure that can efficiently update elements and calculate prefix sums in a table of numbers.
API:
- update(self,i,k) --> update value k to index i
- prefixSum(self,i) --> sum up [index 0, index 1, ..., index i]
- preview(self)
- getSize(self)
- buildFromList(cls, l)
Time Complexity: update & prefixSum, O(logN)
Space Complexity: O(N)
## Convention:
- "key" and "val" are almost the same in this implementation. use term "key" for search and delete a particular node. use term "val" for other cases

weixin_42156940
- 粉丝: 31
最新资源
- 大楼网络系统设计方案.doc
- 数字温度计方案设计书(单片机).doc
- 小议网络营销的利和弊.docx
- 单片机16X16点阵显示方案设计书207.doc
- 局用通信设备中开关电源动态性能的改善技巧.doc
- 我国互联网银行业快速发展微众、网商等银行占据主要市场.docx
- 基于PLC变频恒压供水控制系统方案设计书.doc
- 浅析互联网+背景下网络文化融入高校思政教育.docx
- 高职院校档案信息化的主要问题及解决对策.docx
- (源码)基于Python的AIML聊天机器人系统.zip
- 计算机辅助大学英语学业测试对教学的反拨效应实证研究.docx
- 分层教学在高职计算机教学中的应用研究.docx
- MCS-汇编语言程序设计.ppt
- 单片机期末考试资料汇总.doc
- 探讨如何提高中职计算机办公软件教学的质量.docx
- 基于AI的网络安全威胁演化模型-洞察阐释.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



评论0