Skip to content

Instantly share code, notes, and snippets.

@chaliy
Created February 3, 2014 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaliy/8793186 to your computer and use it in GitHub Desktop.
Save chaliy/8793186 to your computer and use it in GitHub Desktop.
Algorithm course has trees encoded as array, simple routine to draw grapth from it
import pydot
def print_tree(tree):
g1 = pydot.Dot(graph_type='graph')
for i in range(len(tree)):
g1.add_edge(pydot.Edge(i, tree[i]))
g1.write_png('print_tree.png')
# Usage
# print_tree([6,2,6,4,6,6,6,2,4,4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment