MCPcopy Create free account
hub / github.com/Berkeley-CS61B/skeleton-sp23 / fib

Method fib

lab03/src/timing/Experiments.java:26–34  ·  view source on GitHub ↗

Computes the nth Fibonacci number using a slow naive recursive strategy.

(int n)

Source from the content-addressed store, hash-verified

24
25 /** Computes the nth Fibonacci number using a slow naive recursive strategy.*/
26 private static int fib(int n) {
27 if (n < 0) {
28 return 0;
29 }
30 if (n == 1) {
31 return 1;
32 }
33 return fib(n - 1) + fib(n - 2);
34 }
35
36 public static TimingData exampleFibonacciExperiment() {
37 List<Integer> Ns = new ArrayList<>();

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected