2021-02-15 Trees

296 days ago by calkin

d = {0: [1,4,5], 1: [2,6], 2: [3,7], 3: [4,8], 4: [9], 5: [7, 8], 6: [8,9], 7: [9]} G = Graph(d) plot(G) show(G) G=Graph(d) G 
       

show(G) 
       
CollatzTree={} for i in srange(1,27): a=i while a>1: if is_even(a): #if a<50: CollatzTree.update({a:[a/2]}) a=a/2 else: #if a<50: CollatzTree.update({a:[3*a+1]}) a=3*a+1 T=Graph(CollatzTree) show(T) x=T.graphplot(layout='tree', tree_root=1,tree_orientation='up') x.show(figsize=[25,20]) 
       

print(CollatzTree) 
       
{2: [1], 3: [10], 4: [2], 5: [16], 6: [3], 7: [22], 8: [4], 9: [28], 10:
[5], 11: [34], 12: [6], 13: [40], 14: [7], 15: [46], 16: [8], 17: [52],
18: [9], 19: [58], 20: [10], 21: [64], 22: [11], 23: [70], 24: [12], 25:
[76], 26: [13], 28: [14], 29: [88], 32: [16], 34: [17], 35: [106], 38:
[19], 40: [20], 44: [22], 46: [23], 52: [26], 53: [160], 58: [29], 64:
[32], 160: [80], 70: [35], 76: [38], 80: [40], 88: [44], 106: [53]}
{2: [1], 3: [10], 4: [2], 5: [16], 6: [3], 7: [22], 8: [4], 9: [28], 10: [5], 11: [34], 12: [6], 13: [40], 14: [7], 15: [46], 16: [8], 17: [52], 18: [9], 19: [58], 20: [10], 21: [64], 22: [11], 23: [70], 24: [12], 25: [76], 26: [13], 28: [14], 29: [88], 32: [16], 34: [17], 35: [106], 38: [19], 40: [20], 44: [22], 46: [23], 52: [26], 53: [160], 58: [29], 64: [32], 160: [80], 70: [35], 76: [38], 80: [40], 88: [44], 106: [53]}
 
       

How can we used these tree graphs to display factor trees?

What issues will we face?  

1. Need to label vertices with the *same* label!

2. Need to position the vertices left or right appropriately.

Need to use Binary Trees!

T=BinaryTree([None, BinaryTree([None, None])]) 
       
T.show() 
       
G=T.to_ordered_tree_left_branch() 
       
type(G) 
       
<class
'sage.combinat.ordered_tree.OrderedTrees_all_with_category.element_class\
'>
<class 'sage.combinat.ordered_tree.OrderedTrees_all_with_category.element_class'>
show(G) 
       
collatz_tree = {1:[2], 2:[4], 4:[8]}