jweinst1
10/8/2016 - 6:26 AM

questionstrees.py

#Tree practice for Aarsh

#Basic tree class

class Tree:
	
	def __init__(self, value=None, children=[]):
		self.value = value
		self.children = children
		
		
	def append_child(self, value):
		self.children.append(Tree(value))
		

#Problems

#1 

#implement a function that pretty prints a tree. USE RECURSION
def pretty_print(tree):
	pass

#2

#Implement a function that takes a number n, and returns a tree that has a
#width of n children that increases in the number of children by 1 but the value of
#each node decreases by 1, until n is 0. USE RECURSION
def reduc_tree(n):
	pass
		
#EXAMPLE
"""   a = reduc_tree(4)
=> None
   print(pretty_print(a))
 3:{
  2:{
   1:{
0:{}}
      1:{
0:{}}
   }
    2:{
   1:{
0:{}}
      1:{
0:{}}
   }
    2:{
   1:{
0:{}}
      1:{
0:{}}
   }
  }
"""

#3

#Implement a function that counts all the nodes in a tree using recursion 

def count_nodes(tree):
	pass