answersLogoWhite

0

Restating the code fragment in C for clarity:

void f (int n) {

int i, j, k, count = 0;

for (i=0; i<n; ++i) {

for (j=i; j<n; ++j) {

for (k=0; k<3; ++i {

++count;

}

}

}

printf ("For n=%d, count=%d\n", n, count);

}

If we invoke this algorithm,

f (10);

f (100);

we get the following outputs:

n=10, count=1650

n=100, count=1515000

The relationship between n and count is demonstrably quadratic, thus:

T(n) = Θ(n*n).

10*10 is obviously not 1650 (it is 100) and 100*100 is not 1,616,000 (it is 10,000), however the purpose of time-complexity is merely to give an indication of an algorithm's complexity. If we want to express the time-complexity precisely, it would be:

T(n) = Θ(n*n*(n+1)/2*3)

But if we express time-complexities precisely, it becomes much more difficult to compare algorithms. That is, it is much easier to compare algorithms with time-complexity Θ(n*n) and Θ(log n) than it is to use a more precise notation.

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

Do you capitalize a sentence fragment following a colon?

You should not capitalize a sentence fragment following a colon.


Does the following item contain a fragment?

I'm happy to help! Please provide the item you would like me to check for a fragment.


Which is the following is a sentence fragment?

A group of words that cannot stand alone as a sentence


The following is a sentence fragment until we meet next year t or f?

It is true


How do you change the following sentence fragment My best regards honestly and respectfully?

My best regards,


Which one of the group grouping the following groups of words is a fragment?

To determine if a group of words is a fragment, look for a complete thought or a subject-verb pair. A fragment lacks one or both of these elements and does not stand alone as a complete sentence. If you provide the specific groups of words, I can help identify which one is a fragment.


Which of the following statements about okazaki fragment in e coli is true?

They are formed on the lagging strand of DNA.


Which one of the following formed element in the blood is not a cell but actually a fragment of a cell?

Iam not sure but it is plasma


Which of the following best describes how you could fix a sentence fragment that lacks a subject and a verb?

Combine it with another sentence.


Is 'A year that was' a sentence or a fragment?

Fragment.


Is (how are you) a fragment?

It is a fragment that shouldn't be capitalized or punctuated.


What is dfd fragment?

it means definitely found dead fragment, which mean you found dead fragment and do not use it.