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

Function Recursive

math/fibonacci/fibonacci.go:53–59  ·  view source on GitHub ↗

Recursive calculates the n-th fibonacci number recursively by adding the previous two Fibonacci numbers. This algorithm is extremely slow for bigger numbers, but provides a simpler implementation.

(n uint)

Source from the content-addressed store, hash-verified

51// Recursive calculates the n-th fibonacci number recursively by adding the previous two Fibonacci numbers.
52// This algorithm is extremely slow for bigger numbers, but provides a simpler implementation.
53func Recursive(n uint) uint {
54 if n <= 1 {
55 return n
56 }
57
58 return Recursive(n-1) + Recursive(n-2)
59}

Callers 1

TestRecursiveFunction · 0.70

Calls

no outgoing calls

Tested by 1

TestRecursiveFunction · 0.56