Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this lab you will create and submit a single .java file containing a single m

ID: 3833744 • Letter: I

Question

In this lab you will create and submit a single .java file containing a single main method that will be used to call and test each of the following methods : Method 1 Write a method that displays the first n Fibonacci numbers. Your method receives n as parameter. Indicate in comments, what is the Big Oh Notation of the time complexity of this method. Provide Clear Explanation. Method 2 Write a method that determines whether each of the first n Fibonacci numbers is odd or even. Your method receives n as parameter. Indicate in comments, what is the Big Oh Notation of the time complexity of this method. Provide Clear Explanation. Method 3 Write a method that receives an integer n as parameter and display the list of all the pair of Fibonacci numbers which sum is n. For Example, if n =2 your method will display the pair 0 and 2 ; 1 and 1 . Indicate in comments, what is the Big Oh Notation of the time complexity of this method. Provide Clear Explanation. Method 4 Write a method that receives two arrays of integer of different length and displays all the combination of the sum between an element of the first array and element of the second array. Indicate in comments, what is the Big Oh Notation of the time complexity of this method. Provide Clear Explanation. Method 5 Write a method that receives an array of integers with elements sorted in descending orders. This method will ask the user for a value to be searched in this array and will write an algorithm, based on the binary search algorithm, which will find this value. Indicate in comments, what is the Big Oh Notation of the time complexity of this method. Provide Clear Explanation.

Explanation / Answer

CODE:

//CODE:

// Fibonacci Series - Time Complexity = O(n)
public class Fibonacci
{
   // part 1 - Time Complexity = O(n)
   public static void findFibonacciNumbers(int n)
   {
       int i =0;
       int fib[] = new int[n+1];
      
       // first two fibonacci numbers will 0 and 1 always.
       fib[0] = 0;
       System.out.println(fib[0] + " " + findEvenOrOdd(fib[0]));
       fib[1] = 1;
       findEvenOrOdd(fib[i]);
       System.out.println(fib[1] + " " + findEvenOrOdd(fib[1]));
      
       for (i = 2; i <= n; i++)
       {
           // Add the previous 2 numbers in the series
           fib[i] = fib[i-1] + fib[i-2];
           System.out.println(fib[i] + " " + findEvenOrOdd(fib[i]));
       }
   }
  
   // part 2 - find number is even or odd = Time Complexity = O(1)
   public static String findEvenOrOdd(int n){
       if ( n % 2 == 0 )
           return "Even";
       else
           return "Odd";
   }
  
   public static void main (String args[])
   {
       // calculate first 8 fibonacci numbers.
       int n = 9;
      
       // findFibonacciNumbers() function will calculate and print the numbers.
       findFibonacciNumbers(n);
   }
}

OUTPUT:
0 Even
1 Odd
1 Odd
2 Even
3 Odd
5 Odd
8 Even
13 Odd
21 Odd
34 Even

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote