I was task with a problem to write a test program to evaluate the computational complexity (Big O) of the following problem and really dont know where to start.
- A single loop iterated n times
- A nested loop where eaach loop is iterated n times
This is what I was able to produce
for(int i=0; i <n; i++){
// Do stuff
}
The problem now is how to write the test program. Can someone help me out?
From what you described, the complexity of the algo seems to be O(n ^ 2).
It can be possible to try evaluating it “experimentally”: just run the algo with different n values and take the computation times. Then plot the n values on the x axis of a graph and the time values on the y axis. You should now see something approximable with a parabola.