Question: Java Programmig: Needed the most are: Recursion, Anonymous classes, and Lambda expressions. Part I: Recursion 1. If you know that, in mathematics, the Fibonacci numbers,

Java Programmig: Needed the most are: Recursion, Anonymous classes, and Lambda expressions. Part I: Recursion 1. If you know that, in mathematics, the Fibonacci numbers, commonly denoted F, form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is, F0 =0, F1=1 and Fn = Fn-1 + Fn-2

The beginning of the sequence is thus: 0, 1, 1, 2, 3, 5, 8, 13, 21, ... a. Write a recursive function (method) to find the nth number in Fibonacci sequence. b. Write an iterative function (method) to find the nth number in Fibonacci sequence. c. Report the time elapsed by both functions in milliseconds*. The time elapsed by a function is the difference of the time reported after calling the function to the time reported before calling the function.

Java Programmig: Needed the most are: Recursion, Anonymous classes, and Lambda expressions.

*To see the significant difference, try big numbers such as: 40.

Part II: Lambda Expressions 2. Suppose that a functional interface ArrayProcessor is defined as:

Part I: Recursion 1. If you know that, in mathematics, the Fibonacci

In the main method of a class that you create later, we defined a function that returns the length of an array of type double and used it as:

numbers, commonly denoted F, form a sequence, called the Fibonacci sequence, such Now, using the same concept, lambda, you write and use the following functions: a. A function to find the maximum value in an array. b. A function to find the minimum value in an array. c. A function to find the sum of the values in an array. d. A function to find the average of the values in an array.

long start = System.currentTimeMillis(); // your function call long finish = System.currentTimeMillis(); long timeElapsed = finish - start; System.out.println(time Elapsed + " ms"); Fibonacci #40 using recursion function: 102334155 256 ms Fibonacci #40 using Iterative function: 102334155 ms public interface ArrayProcessor { double apply( double[] array ); double[] firstList = { 6, 2.6, 3, 5, 7, 12, 7, 2.5, 10.3, 1.7 }; Array Processor numberOfElements = (array) -> { return array.length; }; System.out.println(numberOfElements.apply(firstList)); //prints 10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!