func main() { inArr := []int{4, 5, 7, 8, 9} t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1) isBST := isBTaBST(t1, MinInt, MaxInt) fmt.Println("Is BST? ", isBST) inArr1 := []int{10, 5, 7, 8, 9} t2 := binarytree.NewMinimalHeightBST(inArr1, 0, len(inArr1)-1) isBST = isBTaBST(t2, MinInt, MaxInt) fmt.Println("Is BST? ", isBST) }
func main() { inArr1 := []int{4, 5, 7, 8, 9, 10, 12, 14, 15, 17, 19, 20} t1 := binarytree.NewMinimalHeightBST(inArr1, 0, len(inArr1)-1) inArr2 := []int{9, 10, 12, 14, 15, 17} t2 := binarytree.NewMinimalHeightBST(inArr2, 0, len(inArr2)-1) isAvail := isT2PresentInT1(t1, t2) fmt.Println("Is T2 Available in T1? ", isAvail) }
func main() { inArr := []int{4, 5, 7, 8, 9, 10, 12, 14, 15, 17, 19, 20} t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1) findAndPrintPath(t1) }
func main() { inArr := []int{4, 5, 7, 8, 9} t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1) binarytree.InOrderTraverse(t1) ancestor := findCommonAncestor(t1, t1.Right) fmt.Println("Common Ancestor : ", ancestor) }
func main() { inArr := []int{4, 5, 7, 8, 9} t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1) binarytree.InOrderTraverse(t1) fmt.Println("Left", t1.Left.Value) //Parent is not set in the tree construction for testing //in_order_successor := getInOrderSuccessor(t1.Left) //fmt.Println("In Order succesor? ", in_order_successor.Value) }
func main() { inArr := []int{4, 5, 7, 8, 9} t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1) binarytree.InOrderTraverse(t1) height := getHeight(t1) fmt.Println(height) fmt.Println("Tree Balanced is ", isBalanced(t1)) }
func main() { inArr := []int{4, 5, 7, 8, 9} t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1) binarytree.InOrderTraverse(t1) //t1 := binarytree.New(100, 1) isBalanced(t1) t2 := binarytree.New(100, 1) isBalanced(t2) }
func main() { inArr := []int{4, 5, 7, 8, 9} t1 := binarytree.NewMinimalHeightBST(inArr, 0, len(inArr)-1) binarytree.InOrderTraverse(t1) var nodeList []*list.List getLevelbasedList(&nodeList, t1, 0) fmt.Println() for _, value := range nodeList { fmt.Print("[ ") for x := value.Front(); x != nil; x = x.Next() { fmt.Print(x.Value.(int), " ") } fmt.Println("]") } }