MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / UsingTree

Function UsingTree

math/factorial/factorial.go:44–55  ·  view source on GitHub ↗

UsingTree This function finds the factorial of a number using a binary tree

(n int)

Source from the content-addressed store, hash-verified

42
43// UsingTree This function finds the factorial of a number using a binary tree
44func UsingTree(n int) (int, error) {
45 if n < 0 {
46 return 0, ErrNegativeArgument
47 }
48 if n == 0 {
49 return 1, nil
50 }
51 if n == 1 || n == 2 {
52 return n, nil
53 }
54 return prodTree(2, n), nil
55}
56
57func prodTree(l int, r int) int {
58 if l > r {

Callers

nothing calls this directly

Calls 1

prodTreeFunction · 0.85

Tested by

no test coverage detected