Help coderanch get a
new server
by contributing to the fundraiser

Jason Reaves

Greenhorn
+ Follow
since Feb 15, 2013
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Jason Reaves

Algorithm books like to be confusing. The for loop in your example will run n-m+1 times so that becomes the complexity and it'll be multiplied by the complexity of the inner loop. I'll try to demonstrate.

I'll use an example of two while loops because basically a while loop comes out to be the same thing as a for loop in time analysis.

Basically the time analysis on a while loop amounts to

twhile being the time of the while loop
tbody being the time of the body of the while loop
tcond being the time of the conditional of the while loop
"r" being how many times the body is to be run

The reason tcond is there at the end is because it will be ran again and become false at the end of loop.

So if you have loops inside of loops for instance:


Then we'll call the first while loop T1while and the second while loop T2while so T1 become


11 years ago
Std C++ wants the array size to be a constant so it's known at compile time. If you need dynamic memory you can do something like.

Alternatively you can look into vectors which allow you to use it as a dynamic array.
c++ reference <vector>
11 years ago
As was said it's due to how the list are compared.
If you want to run the > operator against each pair from the lists you can use zipWith or in the case of [Int] you can sum them and then compare them.

11 years ago