tree

package
v0.0.0-...-bced520 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasPathSum

func HasPathSum(root *Node[int], targetSum int) bool

HasPathSum returns true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.

func InorderTraversal

func InorderTraversal[T any](root *Node[T]) []T

InorderTraversal returns inorder traversal of its nodes' values.

func IsBalanced

func IsBalanced[T any](root *Node[T]) bool

IsBalanced return true if given tree is balanced.

func IsSameTree

func IsSameTree[T any](p *Node[T], q *Node[T], eq func(a, b T) bool) bool

func IsSymmetric

func IsSymmetric[T any](root *Node[T], eq func(a, b T) bool) bool

func MaxAncestorDiff

func MaxAncestorDiff(root *Node[int]) int

func MaxDepth

func MaxDepth[T any](root *Node[T]) int

func MinDepth

func MinDepth[T any](root *Node[T]) int

MinDepth returns the min depth of tree. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.

func PostorderTraversal

func PostorderTraversal[T any](root *Node[T]) []T

PostorderTraversal returns postorder traversal of its nodes' values.

func PreorderTraversal

func PreorderTraversal[T any](root *Node[T]) []T

PreorderTraversal returns preorder traversal of its nodes' values.

Types

type Node

type Node[T any] struct {
	Val   T
	Left  *Node[T]
	Right *Node[T]
}

func FromSortedArray

func FromSortedArray[T any](nums []T) *Node[T]

FromSortedArray returns a binary search tree from given sorted array.

func Invert

func Invert[T any](root *Node[T]) *Node[T]

Invert inverts tree, and returns its root.

Jump to

Keyboard shortcuts

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