def coefficientOfRelationship(id1,id2): if( not idExists(id1)): return (id1 + " does not exist") if( not idExists(id2)): return (id2 + " does not exist") if (id1 == id2): return 1 print("writing lineage list1") lineageList = idToLineageList(id1) print("filling tree1 from list") tree1 = lineageListToTree(lineageList) cleanUpTupleTree(tree1) print("writing lineage list2") lineageList = idToLineageList(id2) print("filling tree2 from list") tree2 = lineageListToTree(lineageList) cleanUpTupleTree(tree2) hypotheticalChild = BinaryTree("Hypothetical Child") hypotheticalChild.setLeft(tree1) hypotheticalChild.setRight(tree2) return 2 * COI(hypotheticalChild)
# Create initial leaf nodes a = BinaryTree("A") b = BinaryTree("B") c = BinaryTree("C") d = BinaryTree("D") e = BinaryTree("E") f = BinaryTree("F") g = BinaryTree("G") # Build the tree from the bottom up, where # d is the root node of the entire tree # Build and set the left subtree of d b.setLeft(a) b.setRight(c) d.setLeft(b) # Build and set the right subtree of d f.setLeft(e) f.setRight(g) d.setRight(f) def size(tree): if tree.isEmpty(): return 0 else: return 1 + size(tree.getLeft()) + size(tree.getRight()) def frontier(tree): """Returns a list containing the leaf nodes
# Create initial leaf nodes a = BinaryTree("A") b = BinaryTree("B") c = BinaryTree("C") d = BinaryTree("D") e = BinaryTree("E") f = BinaryTree("F") g = BinaryTree("G") # Build the tree from the bottom up, where # d is the root node of the entire tree # Build and set the left subtree of d b.setLeft(a) b.setRight(c) d.setLeft(b) # Build and set the right subtree of d f.setLeft(e) f.setRight(g) d.setRight(f) def size(tree): if tree.isEmpty(): return 0 else: return 1 + size(tree.getLeft()) + size(tree.getRight())