Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose that your implementation of a particular algorithm appears in C++ as for

ID: 3531960 • Letter: S

Question


Suppose that your implementation of a particular algorithm appears in C++ as

for (int pass = 1; pass <= n; ++ index)

   { for (int index = 0; index < n; ++ index)

        { for (int count = 1; count < 10; ++ count)

                    {

                        . . .

                                } // end for

                       } // end for

        } // end for

The previous code shows only the repetition in the algorithm, not the computations that occur within the loops. These computations, however, are independent of n. What is the order of the algorithm? Justify your answer.

Explanation / Answer

Outer for loop runs for 'n' times and
for each instance of outer for loop , the middle for loop runs for 'n' times
and for each instance of middle for loop ,the inner for loop runs for '9' times.
so order of algo = O(n*n*9)
= O(9n^2)
= O(n^2)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote