Dawlat H.

asked • 02/05/24

Algorithm Runtime

I’m confused on the runtime for an if-statement and how to find it. This is my work so far, can someone explain what runtimes for if statements are like and how they work. 


Give an analysis of the running time (Big-Oh will do)

sum = 0; // O(1)

for( i = 1; i < n; ++i ) // O(N)

for( j = 1; j < i * i; ++j ) // O(N) * O(N) = O(N)

if( j % i == 0 ) //

for( k = 0; k < j; ++k ) //

++sum; // O(1)


Runtime =

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.