How to find computational complexity?

AI Thread Summary
To determine the computational complexity of a program, start by analyzing the structure of the code, particularly focusing on nested loops. For example, three nested loops each iterating from 1 to x with constant-time operations result in a complexity of O(n^3). When dealing with bignums, the cost of operations varies based on the size of the numbers, often leading to complexities like O(x(log x)^2) for operations such as schoolbook multiplication. For further understanding, refer to programming language standards that outline the asymptotic running times of standard library functions. A highly recommended resource for deeper insights into algorithm analysis is "Introduction to Algorithms" by Cormen, Leiserson, Rivest, and Stein (CLRS).
Coolphreak
Messages
44
Reaction score
0
If i have a program, how can i find the computational complexity? is there some other program i can run in the background?
 
Technology news on Phys.org
A first step would be counting the nested loops and looking at the number of times they execute. If you have three nested loops, each running from 1 to x, and inside the three you have operations taking constant time (i.e. not dependent on the size of any variable) then the complexity is \mathcal{O}(n^3).

If you're using bignums or the like you'll have to look into how much each operation costs based on the size of the numbers -- that's usually log(x)^k log(log(x))^n for some k and n. If you have a loop from 1 to x doing schoolbook multiplication on a bignum of size x, that's complexity \mathcal{O}(x(\log x)^2).
 
Last edited:
thanks for your help. can u point me to some resource where i can look some of this stuff up?
 
If you're using standard library functions, most programming language standards will specify the mandatory asymptotic running time in the standard. If you're wanting to analyse your own code, then a good book (the standard in universities, pretty much), is Introduction to Algorithms by CLRS.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top