Skip to content

fanchi/drawtree

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

drawtree

Latest PyPI version

Draw binary tree in plain text

Usage

Draw tree from level order traversal, '#' signifies a path terminator where no node exists below.

from drawtree import draw_level_order
draw_level_order('{3,9,20,#,#,15,7}')
  3
 / \
9  20
   / \
  15  7

Draw random binary search tree

from drawtree import draw_random_bst
draw_random_bst(10)
    64
    / \
   /   \
  4    66
   \     \
   37    70
   / \
  8  51
 / \
6  12
     \
     21

Draw binary search tree from integer array

from drawtree import draw_bst
nums = [55, 30, 10, 5, 2, 20, 15, 25, 40, 35, 70, 60, 80, 75, 95]
draw_bst(nums)
             55
             / \
            /   \
           /     \
          /       \
         30       70
        / \       / \
       /   \     /   \
      /     \   60   80
     10     40       / \
    / \     /       /   \
   /   \   35      75   95
  5    20
 /     / \
2     /   \
     15   25

Installation

To install drawtree, simply:

$ pip install drawtree

Licence

MIT

Reference

Draw tree

Authors

drawtree was written by Madhusudan Banik.

About

Draw binary tree in plain text

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%