bavetta / binary-tree

Self-Balancing Binary Search Tree in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Self-Balancing Binary Tree

Python binary tree module that is self-balancing.

Note: There are probably better libraries that do what you want. Python "bisect" library performs binary search on lists. Additionaly, the "blist" package is awesome and includes "sortedlist" and "sorteddict" among others.

What Problem This Solves

  • Small space, Ave: O(n), Max: O(n)
  • Fast search, Ave: O(log n), Max: O(log n)
  • Fast insert, Ave: O(log n), Max: O(log n)
  • Fast delete, Ave: O(log n), Max: O(log n)
  • Objects with duplicate values may be added

How This Solves It

Uses AVL trees.

Usage

New tree

tree = BinaryTree()

Insert Entity into the tree

tree.insert(5, "optional unique ID")

About

Self-Balancing Binary Search Tree in Python

License:MIT License


Languages

Language:Python 100.0%