Given a real number x and a positive integer k, determine the
number of multiplications used to find x^(2^i) starting with x and
successively squaring ( to find x^2, x^4 and so on). Is this a more
efficient way to find x^(2^i) than by multiplying x by itself the
appropriate number of times?
Give the C++ code to work this problem, if possible with recursion,
if not explain why?
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include <iostream>
using namespace std;
double calculate(double x,int k)
{
if(k==0)
return x;
return calculate(x*x,k-1);
}
int main()
{
cout<<"Enter x: ";
double x;
int k;
cin>>x;
cout<<"Enter k: ";
cin>>k;
cout<<"x^2^k is "<<calculate(x,k)<<endl;
return 0;
}
Kindly revert for any queries
Thanks.
Given a real number x and a positive integer k, determine the number of multiplications used...
Let k 21 be a positive integer, and let r R be a non-zero real number. For any real number e, we would like to show that for all 0 SjSk-, the function satisfies the advancement operator equation (A -r)f0 (a) Show that this is true whenever J-0. You can use the fact that f(n) = crn satisfies (A-r)f = 0. (b) Suppose fm n) satisfies the equation when m s k-2 for every choice of c. Show that )...
DEFINITION: For a positive integer n, τ(n) is the number of positive divisors of n and σ(n) is the sum of those divisors. 4. The goal of this problem is to prove the inequality in part (b), that o(1)+(2)+...+on) < nº for each positive integer n. The first part is a stepping-stone for that. (a) (10 points.) Fix positive integers n and k with 1 <ksn. (i) For which integers i with 1 <i<n is k a term in the...
Write an algorithm that takes two strings X and Y and a positive integer k as input, and determines whether Y can be turned into X by at most k insertions or deletions. For example: let X = “abacad", Y = “cebacad" and k = 3 then your algorithm should give a yes answer because Y can be turned into X in 3 steps by a left-to-right processing as follows: delete leftmost c delete “e" insert “a" Give an tight...
Question 8: For any integer n 20 and any real number x with 0<<1, define the function (Using the ratio test from calculus, it can be shown that this infinite series converges for any fixed integer n.) Determine a closed form expression for Fo(x). (You may use any result that was proven in class.) Let n 21 be an integer and let r be a real number with 0<< 1. Prove that 'n-1(2), n where 1 denotes the derivative of...
Given a positive integer n and a real number θ E (0,7), prove that sin n θ 2 sin θ where γ is the circle of radius 2 centered at the origin, oriented counterclockwise. Given a positive integer n and a real number θ E (0,7), prove that sin n θ 2 sin θ where γ is the circle of radius 2 centered at the origin, oriented counterclockwise.
COMP Discrete Structures: Please answer completely and clearly. (3). (5). x) (4 points) If k is a positive integer, a k-coloring of a graph G is an assignment of one of k possible colors to each of the vertices/edges of G so that adjacent vertices/edges have different colors. Draw pictures of each of the following (a) A 4-coloring of the edges of the Petersen graph. (b) A 3-coloring of the vertices of the Petersen graph. (e) A 2-coloring (d) A...
(1) Give a formula for SUM{i} [i changes from i=a to i=n], where a is an integer between 1 and n. (2) Suppose Algorithm-1 does f(n) = n**2 + 4n steps in the worst case, and Algorithm-2 does g(n) = 29n + 3 steps in the worst case, for inputs of size n. For what input sizes is Algorithm-1 faster than Algorithm-2 (in the worst case)? (3) Prove or disprove: SUM{i**2} [where i changes from i=1 to i=n] ϵ tetha(n**2)....
QUESTION C. (a) Let k be a field and let n be a positive integer. Define what is meant by a monomial ideal in k[x,...,zn]. 2. (b) State what it means for a ring R to be Noetherian. (c) State Hilbert's basis theorem. Give a proof of Hilbert's basis theorem using the fact if k is a field the polynomial ring kli,..., In] is Noetherian. 1S (a) Let k be a field and let n be a positive integer. Define...
A random variable X has a distribution with probability function f(x) = K(nx)2x for x = 0,1,2,...,n where n is a positive integer. a. Find the constant k. b. Find the expected value M(S) = E(esX) as a function of the real numbers s. Compare the values of the derivative of this function M'(0) at 0 and the expected value of a random variable having the probability function above. c. What distribution has probability function f(x)? Let X1, X2 be independent random variables both...
3.11 Theorem. Suppose f(x)-a"x" + an-lx"-+ + ao is a poly- nomial of degree n > 0 and suppose an > 0. Then there is an integer k such that ifx >k, then f(x)> 0. Note: We are only assuming that the leading coefficient an is greater than zero. The other coefficients may be positive or negative or zero. The next theorem extends the idea that polynomials get positive and roughly states that not only do they get positive, but...