Giter VIP home page Giter VIP logo

py-bst's Introduction

PyBST

PyBST implements Binary Trees, AVL Trees, Splay Trees, and Red Black Trees in Python. Furthermore, PyBST provides a module for plotting these trees using networkx and matplotlib.

Tree Classes Provided:

  • BSTree - represents an unbalanced Binary Search Tree
  • AVLTree - represents a balanced AVL Tree
  • SplayTree - represents an adjusted Splay Tree
  • RBTree - represents a balanced Red Black Tree

Constructor:

Let Tree represent one of the provided tree classes mentioned above.

  • Tree() - > Creates a new empty tree
  • Tree(seq) -> Creates a new empty tree from seq [(key1,val1),(key2,val2),...,(keyn,valn)]

Methods:

Tree Methods

  • is_valid() -> Produces True if Tree is a valid tree of its type, else False.
  • preorder() -> Produces a sequence of the Nodes in Tree in preorder.
  • inorder() -> Produces a sequence of the Nodes in Tree in inorder.
  • postorder() -> Produces a sequence of the Nodes in Tree in postorder.
  • levelorder() -> Produces a sequence of the Nodes in Tree in levelorder.
  • get_node(key) -> Produces the Node in Tree with key attribute key.
  • insert(key,val) <==> Tree[key] = value. Inserts a new Node with key attribute key and value attribute val into Tree.
  • insert_from(seq) -> Inserts keys and values from seq [(key1,val1),(key2,val2),...,(keyn,valn)] into Tree.
  • get_max() <==> max(Tree). Produces the Node with the maximum key in Tree.
  • get_min() <==> min(Tree). Produces the Node with the minimum key in Tree.
  • get_element_count <==> len(Tree). Produces the number of elements in Tree.
  • get_height() -> Produces the height of Tree.
  • delete(key) <==> del Tree[key]. Deletes the Node with key attribute key from Tree.
  • delete_from(seq) -> Deletes Nodes with keys from seq [key1,key2,...,keyn] from Tree.

Plotting Methods (draw Module)

  • plot_tree(Tree) -> Provides a visual representation of Tree via plotting it using networkx and matplotlib.

Dependencies

PyBST requires no external dependencies for the tree classes and their methods themselves. However, note that the following packages are required for tree plotting:

Installation

From source:

python setup.py install

Using easy install:

easy_install pybst

Resources

py-bst's People

Contributors

tylersandman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.