SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 2 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Engineering Posted 23 Oct 2017 My Price 9.00

Consider the following iterative function:

I need help with my homework, here are the questions below:

 

1. Consider the following iterative function:

 

int pentagonal(int n) {

 

int result = 0;

 

for (int i = 1; i <= n; i++)

 

result += 3 * i - 2;

 

return result;

 

}

Rewrite the function pentagonal using recursion and add preconditions and postconditions as comments. Then prove by induction that the recursive function you wrote is correct.

2. Suppose the number of steps required in the worst case for two algorithms are as follows:

Algorithm 1: f(n) = 10n 2 + 6

Algorithm 2: g(n) = 21n + 7

 

Determine at what point algorithm 2 becomes more efficient than algorithm 1.

 

3. Given the following function that evaluates a polynomial whose coefficients are stored in an array:

 

double evaluate(double[] coefficients, double x) {

double result = coefficients[0];

 

double power = 1;

 

for (int i = 1; i < array.length; i++)

 

{ power = power * x;

 

result = result + coefficients[i] * power;

 

}

 

return result;

 

}

 

Let n be the length of the array. Determine the number of additions and multiplications that are performed in the worst case as a function of n.

 

4. Given the following recursive binary search algorithm for finding an element in a sorted array of integers:

 

int recursiveBinarySearch(int[] array, int target, int left, int right) {

 

if (left > right) return -1; int middle = (left + right) / 2;

 

if (array[middle] == target) return middle;

 

if (array[middle] > target) return recursiveBinarySearch(array, target, left, middle - 1);

 

return recursiveBinarySearch(array, target, middle + 1, right);

 

}

Answers

(5)
Status NEW Posted 23 Oct 2017 02:10 PM My Price 9.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)