trees

package
v0.0.0-...-03d60e9 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBinarySearchTree

func IsBinarySearchTree[T int](root *Node[T]) bool

func ListOfDepths

func ListOfDepths[T comparable](root *Node[T], list []*linkedlists.Node[T], depth int) []*linkedlists.Node[T]

Implement a function to check if a binary tree is balanced. For the purpose of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.

input tree:

(13)

output list:

[1]

input tree:

 (25)
/

(13)

    \
	 (9)

output list:

[0] - [13] [1] - [9]->[25]

input tree:

     (29)
    /
 (25)
 /  \
/    (21)

(13)

    \
     \
	 (9)

output list:

[0] - [13] [1] - [9]->[25] [2] - [21]->[29]

Types

type Node

type Node[T comparable] struct {
	// contains filtered or unexported fields
}

func CreateNode

func CreateNode[T comparable](data T, childNodes ...*Node[T]) *Node[T]

func TreeifySortedArray

func TreeifySortedArray[T comparable](a []T, start int, end int) *Node[T]

func (*Node[T]) Equal

func (tree *Node[T]) Equal(otherTree *Node[T]) bool

func (*Node[T]) GetBalancedTreeHeight

func (root *Node[T]) GetBalancedTreeHeight() (int, bool)

Implement a function to check if a binary tree is balanced. For the purpose of this question, a balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ by more than one.

func (*Node[T]) Print

func (tree *Node[T]) Print(out io.Writer)

func (*Node[T]) PrintHelper

func (tree *Node[T]) PrintHelper(space int, out io.Writer)

type ParentedNode

type ParentedNode[T comparable] struct {
	// contains filtered or unexported fields
}

func CreateParentedNode

func CreateParentedNode[T comparable](data T, childNodes ...*ParentedNode[T]) *ParentedNode[T]

func NextInOrderTraversal

func NextInOrderTraversal[T comparable](node *ParentedNode[T]) *ParentedNode[T]

Jump to

Keyboard shortcuts

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