-3

I am trying to analyze the algorithm Product: multiply two n-bits binary numbers x and y.

function Product(x, y); 
 1. prod = 0;
 2. while y not eq 0
 3.     y = y -1;
 4.     prod = prod + x; 
    return prod;

Assume: n = |x| = |y|
Give the worst case time T(n) function for algorithm Product.
Express T(n) in terms of a big-Θ function in n.
Analysis:

T(n) = c1 + n + c2 + c3

I would appreciate it if someone could explain how to use big-Θ to express T(n).

greybeard
  • 1,041
  • 2
  • 9
  • 23
Evan Gertis
  • 105
  • 4

2 Answers2

0

Answer these two questions: How many iterations when n = 1 billion? How many iterations when n = -1?

With that you should have no problem answering your question.

gnasher729
  • 29,996
  • 34
  • 54
0

line 1: c1 line 2: n line 3: c2 line 4: c3 line 5: c4

T(n) = c1 + n + c2n + c3n + c4n T(n) = theta(n)

Evan Gertis
  • 105
  • 4