MCPcopy Create free account
hub / github.com/careercup/ctci / NewMinimalHeightBST

Function NewMinimalHeightBST

go/chapter04/binarytree/binarytree.go:91–101  ·  view source on GitHub ↗

NewMinimalHeightBST gives the minimal height tree from the given sorted array

(arr []int, low int, high int)

Source from the content-addressed store, hash-verified

89
90//NewMinimalHeightBST gives the minimal height tree from the given sorted array
91func NewMinimalHeightBST(arr []int, low int, high int) *Tree {
92 if high < low {
93 return nil
94 }
95 mid := (low + high) / 2
96 t1 := NewTree()
97 t1.Value = arr[mid]
98 t1.Left = NewMinimalHeightBST(arr, low, mid-1)
99 t1.Right = NewMinimalHeightBST(arr, mid+1, high)
100 return t1
101}
102
103//Traverse the tree using in-order traversal
104func InOrderTraverse(t *Tree) {

Callers 1

mainFunction · 0.85

Calls 1

NewTreeFunction · 0.70

Tested by

no test coverage detected