int fact(int N) {
j=1; prod=1;
while (j<=N) {
j=j+1; prod=prod*j;
}
return prod;
}
uniform cost v/s logarithmic cost
Page 1 of 11 Replies - 126 Views - Last Post: 08 February 2013 - 10:52 AM
#1
uniform cost v/s logarithmic cost
Posted 08 February 2013 - 09:37 AM
can anyone explain me the time complexity of factorial function if we follow RAM model and if we follow logarithmic cost concept.
Replies To: uniform cost v/s logarithmic cost
#2
Re: uniform cost v/s logarithmic cost
Posted 08 February 2013 - 10:52 AM
The logarithmic cost concept means each operation has a cost that is proportional to the size of the input. 0 + 1 will cost 1 because all operations will execute over 1 bit, but 100000 + 1 will cost 6 because the operation will have to loop across 6 bits. You will have to figure out how the size of j and prod scale accross all iterations to find the runtime.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|