Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago