How to find computational complexity?

In summary, to find the computational complexity of a program, you can start by counting the nested loops and their number of executions. For operations that are not dependent on variable size, the complexity is \mathcal{O}(n^3). If using bignums, the complexity is usually \mathcal{O}(x(\log x)^2). It is also possible to look up standard library functions for their mandatory asymptotic running time, or refer to a book such as Introduction to Algorithms by CLRS for analyzing your own code.
  • #1
Coolphreak
46
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
  • #2
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 [itex]\mathcal{O}(n^3)[/itex].

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 [itex]\mathcal{O}(x(\log x)^2)[/itex].
 
Last edited:
  • #3
thanks for your help. can u point me to some resource where i can look some of this stuff up?
 
  • #4
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.
 

1. What is computational complexity?

Computational complexity refers to the measurement of the amount of time and space required to solve a problem using a computer. It is a fundamental concept in computer science and helps to determine the efficiency and scalability of algorithms.

2. How is computational complexity calculated?

The most commonly used metric for measuring computational complexity is Big O notation, which represents the worst-case scenario for the time or space required to solve a problem. It is calculated by analyzing the number of operations performed by an algorithm as the input size grows.

3. What factors affect computational complexity?

The main factors that affect computational complexity are the size of the input data, the algorithm used to solve the problem, and the hardware and software environment in which the algorithm is run. Other factors such as the quality of the code and the efficiency of the programming language can also have an impact.

4. How can I estimate the computational complexity of an algorithm?

There are several methods for estimating the computational complexity of an algorithm, including analyzing the algorithm's code, running experiments on different input sizes, and using mathematical proofs. It is also helpful to have a strong understanding of different algorithms and their corresponding complexities.

5. Why is understanding computational complexity important?

Understanding computational complexity is crucial for designing efficient algorithms and writing high-performance code. It helps to identify bottlenecks and optimize algorithms for better time and space usage, which is essential in fields such as artificial intelligence, data science, and software engineering.

Similar threads

  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
7
Views
424
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
10
Views
2K
  • Programming and Computer Science
Replies
29
Views
3K
  • Programming and Computer Science
Replies
5
Views
387
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
1
Views
638
  • Programming and Computer Science
Replies
1
Views
584
  • Programming and Computer Science
Replies
16
Views
1K
Back
Top