Question: Brute Force and Exclude & Conquer Recursive Algorithms In the following problems, use the General Solution of 1st Order Linear Recurrence T(n)= a, T(n-1)+ bn,


Brute Force and Exclude & Conquer Recursive Algorithms In the following problems, use the General Solution of 1st Order Linear Recurrence T(n)= a, T(n-1)+ bn, given T(0) or T(1) with the following solutions: Successive substitution gives for the cases of T(0) given and T(1) given: T(n)=T(0) la; + Eb; II a;+b. T(n)=T(1) IIa, + Eb II a;+by i=/ i=1 j=i+1 i=2 i=2 j=i+1 4. (30 points) An integer n is prime iff n >= 2 and n's only factors (divisors) are 1 and itself. Consider a function Factor_In_Range (k , n) to return true iff some integer in the range k to n-1 divides n with no remainder. In this case, a test of whether n is prime or not can be done by the simple function: boolean is Prime (int n) { return ((n > 1) && !Factor_In_Range(2, n)); } A Brute Force recursive function Factor_In_Range (k, n) can be designed as follows: Factor_In_Range (k, n) { If the range is empty (i.e. k >=n) return false else if k divides n with no remainder, return true else check to see if there is a factor in the range starting with k+1 } Implement the above two functions. Show the results of running the algorithm on the integers n from 1009 to 1021. Find T(n) = number of comparisons + number of arithmetic operations used by the algorithms in case n is prime
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
