2

given the following problem from CLRS algo book.

For each function f (n) and time t in the following table, determine the largest size n of a problem that can be solved in time t, assuming that the algorithm to solve the problem takes f(n) microseconds.

  1. how can one calculate n for f(n)=nlog(n) when time is 1 second?
  2. how can one calculate n for f(n)=n! when time is 1 second?
ilim
  • 4,477
  • 7
  • 27
  • 46
user119020
  • 413
  • 1
  • 3
  • 13

2 Answers2

1

It is mentioned that the algorithm takes f(n) microseconds. Then, one may consider that algorithm to consist of f(n) steps each of which takes 1 microsecond.

The questions given state that relevant f(n) values are bound by 1 second. (i.e. 106 microseconds) Then, since you are looking for the largest n possible to fulfill those conditions, your questions boil down to the inequalities given below.

1) f(n) = nlog(n) <= 106

2) f(n) = n! <= 106

The rest, I believe, is mainly juggling with algebra and logarithmic equations to find the relevant values.

ilim
  • 4,477
  • 7
  • 27
  • 46
0

In first case, You can refer to Example of newtons method to calculate cube root Newton’s method to approximate the roots or Lambert W Function. It may help to calculate value of n. As per the my findings mostly there is no other analytical approach can help.

In second case, python script can help to calculate n with manual approch.

def calFact(n):
    if(n == 0 or n==1):
        return n
    return n*calFact(n-1)

nVal=1
while(calFact(nVal)<1000000):         # f(n) = n! * 10^-6 sec
    nVal=nVal+1                       # 10^6 = n!

print(nVal)

So in this case we are trying to find out n such that n! is equal to or near to 10^6.