procedure polynomial (c, a0,a1, …, an)
power :=1
y≔a0
for i=1 to n
power≔power*c
y≔y+ai*power
return y
Find a big-O estimate for the number of additions and multiplications used by this algorithm.
This algorithm uses exactly n additions(Last line of for loop) and 2n multiplications (Once in each line of the for loop).
Big O notation should represent the growth rate of the function in the algorithm as per the input size (Here it is 'n').
Therefore, the complexity of this algorithm is O(n) which is polynomial time.
) Consider the following algorithm procedure polynomial (c, a0,a1, …, an) power :=1 y≔a0...
procedure polynomial (?,?0,?1,…,??) ?????∶=1 ?≔?0 ??? ?=1 ?? ? ?????≔?????∗? ?≔?+??∗????? ?????? ? Find a big-? estimate for the number of additions and multiplications used by this algorithm.
Show that the number of multiplications used in this algorithm is Consider the following algorithm: procedure multiplications(n: positive integer) for i := 1 to n for j:-1 to i t_2.t return t O (n2) 7l
consider this segment of an algorithm: for i := 1 ton n for j:=1 to n top:=ij+j+10 a. find a function f(n) that counts the number of multiplication and additions performed in this segment. b. Give a big O estimate for the number of additions and multiplications used in the segment
i=n Consider the following procedure to evaluate a polynomial a;x' at x = C. i = 0 procedure poly(ca ,...an power + 1 y cao for i from iton power + power * y+y+a; power return y where + denotes assignment, * denotes multiplication. Evaluate 3x2 + x + 1 at x = 2 by stepping through the algorithm.
Horner: Given the coefficients of a polynomial a0, a1, . . . , an, and a real number x0, find P(x0), P′ (x0), P′′(x0), P(3)(x0), . . . , P(n) (x0) Sample input representing P(x) = 2 + 3x−x 2 + 2x 3 , x0 = 3.5: 3 2 3 -1 2 3.5 the first number is the degree of the polynomial (n), the coefficients are in order a0, a1, . . . , an, the last number is x0....
3) [16 points totall Consider the following algorithm: int SillyCalc (int n) { int i; int Num, answer; if (n < 4) 10; return n+ else f SillyCalc(Ln/4) answer Num Num 10 for (i-2; i<=n-1; i++) Num + = answer + answer; answer return answer } Do a worst case analysis of this algorithm, counting additions only (but not loop counter additions) as the basic operation counted, and assuming that n is a power of 2, i.e. that n- 2*...
What is the time-complexity of the algorithm abc? Procedure abc(n: integer) s := 0 i :=1 while i ≤ n s := s+1 i := 2*i return s consider the following algorithm: Procedure foo(n: integer) m := 1 for i := 1 to n for j :=1 to i2m:=m*1 return m c.) Find a formula that describes the number of operations the algorithm foo takes for every input n? d.)Express the running time complexity of foo using big-O/big-
8. Consider the following algorithm, which finds the sum of all of the integers in a list procedure sum(n: positive integer, a1, a2,..., an : integers) for i: 1 to n return S (a) Suppose the value for n is 4 and the elements of the list are 3, 5,-2,4. List assigned to s as the procedure is executed. (You can list the the values that are values assigned to all variables if you wish) b) When a list of...
Discrete Math Give a big-Theta estimate for the number of additions in the following algorithm a) procedure f (n: integer) bar = 0; for i = 1 to n^3 for j = 1 to n^2 bar = bar + i + j return bar b) Consider the procedure T given below. procedure T (n: positive integer) if n = 1 return 2 for i = 1 to n^3 x = x + x + x return T(/4) + T(/4) +...
Question 1: Complexity Take a look at the following algorithm written in pseudocode: procedure mystery(a1, a2, …, an: integer) i := 1 while (i < n and ai ≤ ai+1) i := i + 1 if i == n then print “Yes!” else print “No!” What property of the input sequence {an} does this algorithm test? What is the computational complexity of this algorithm, i.e., the number of comparisons being computed as a function of the input size n? Provide...