How to convert list data into Binary Search Tree(BST) with graph manner in python?

599 Views Asked by At

I want to create a Binary Search Tree(BST) from list of data with graphical manner in python.I used the following code as

import pydot

from binarytree import build

values = [3, 5, 2, 1, 4,14]

tree = build(values)

print(tree)

print(tree.values)

graph = pydot.Dot(graph_type='graph')

for i in tree.values:

edge = pydot.Edge(i, i+1)

graph.add_edge(edge)

graph.write_png('example1_graph.png')

I got the output in python environment as

enter image description here

and in png format as

enter image description here

But I want the output as in binary tree format with graphical manner as follows

enter image description here

How can I convert the tree(code variable) values in to a graphical BST format? (Your answer may be using graphviz,matplotlib package also) Thanks in advance.

0

There are 0 best solutions below