trees

package
v0.0.0-...-35d7ddc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2021 License: MIT Imports: 4 Imported by: 0

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

func TestHeightBalancedBinaryTree(t *testing.T)

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 CreateRandBT

func CreateRandBT() *BinaryTree

CreateRandBT Creates a Random Binary Tree

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL