Documentation ¶
Overview ¶
Height Balanced Binary Tree You're given the root node of a Binary Tree. Write a function that returns true if this Binary Tree is height balanced and false if it isn't.
A Binary Tree is height balanced if for each node in the tree, the difference between the height of its left subtree and the height of its right subtree is at most 1.
Each BinaryTree node has an integer value, a left child node, and a right child node. Children nodes can either be BinaryTree nodes themselves or None / null.
Sample Input tree = 1
/ \ 2 3 / \ \ 4 5 6 / \ 7 8
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HeightBalancedBinaryTree ¶
func HeightBalancedBinaryTree(tree *BinaryTree) bool
HeightBalancedBinaryTree logic
func TestHeightBalancedBinaryTree ¶
TestHeightBalancedBinaryTree tests
func TraverseInOrder ¶
func TraverseInOrder(t *BinaryTree)
TraverseInOrder : traverses the given tree inorder i.e., LeftNode CurrentNode RightNode
func TraversePostOrder ¶
func TraversePostOrder(t *BinaryTree)
TraversePostOrder : traverses the given tree postorder i.e., LeftNode RightNode CurrentNode
func TraversePreOrder ¶
func TraversePreOrder(t *BinaryTree)
TraversePreOrder : traverses the given tree preorder i.e., CurrentNode LeftNode RightNode
Types ¶
type BinaryTree ¶
type BinaryTree struct { Value int Left, Right *BinaryTree }
BinaryTree node
func NewBinaryTree ¶
func NewBinaryTree(root int, values ...int) *BinaryTree
NewBinaryTree creates new binary tree with given nodes
func (*BinaryTree) Insert ¶
func (tree *BinaryTree) Insert(values []int, i int) *BinaryTree
Insert inserts the values into the tree