Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 528

Complexity of this function

$
0
0

I would like to know how to properly determinate the complexity of this function :

let rec fact n =  match n with  | 0 -> 1  | n -> n * fact (n - 1)let biggest_factorial_below n =  let i = ref 1 in  while (fact !i < n) do    i := !i + 1;  done;  !i

After some reflection, i found that the complexity might be O(log(n)^2).Can you tell me if it's true or wrong?

I tried to use the Sterling approximation to find the biggest I to have i! > n ,so I find that i is proportional to log(n). I know that fact(n) is O(n) so O(1) + O(2) + ... + O(i) = O(i^2)) so the complexity is O(log(n)^2).

(Sorry for my English, I'm not native)


Viewing all articles
Browse latest Browse all 528

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>