Computational complexity of Fibonacci Sequence

I understand Big-O notation, but I don’t know how to calculate it for many functions. In particular, I’ve been trying to figure out the computational complexity of the naive version of the Fibonacci sequence: int Fibonacci(int n) { if (n <= 1) return n; else return Fibonacci(n – 1) + Fibonacci(n – 2); } What … Read more

If strings are immutable in .NET, then why does Substring take O(n) time?

Given that strings are immutable in .NET, I’m wondering why they have been designed such that string.Substring() takes O(substring.Length) time, instead of O(1)? i.e. what were the tradeoffs, if any? 5 Answers 5 UPDATE: I liked this question so much, I just blogged it. See Strings, immutability and persistence The short answer is: O(n) is … Read more

What does O(log n) mean exactly?

I am learning about Big O Notation running times and amortized times. I understand the notion of O(n) linear time, meaning that the size of the input affects the growth of the algorithm proportionally…and the same goes for, for example, quadratic time O(n2) etc..even algorithms, such as permutation generators, with O(n!) times, that grow by … Read more