Find the time complexity for the following algorithm Procedu

Find the time complexity for the following algorithm:

Procedure: printer2 (n: posotive integer)

while n 1

Print \"hello\" ;

n:=[n/3]

Hint: For simplicity, you may assume n= 3k.

Solution

I\'m assuming that n = 3^k


Everytime in the loop, the value of n is decreasing by a factor of 3.
After sometime, the value of n will become 1.

So,
n / 3^k = 1,
where k = number of iterations.

So, n = 3^k
So, k = log(n) {with base of log = 3}
So, time complexity = theta(log(n)) {with base of log = 3}

Find the time complexity for the following algorithm: Procedure: printer2 (n: posotive integer) while n 1 Print \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site