Determine the growth function and order of the following code fragment:
What will be an ideal response?
```
for (int count = 0; count < n; count ++)
{
for (int count2 = 0; count2 < n; count2 = count2 + 2)
{
System.out.println(count, count2);
}
}
```for (int count = 0; count < n; count ++)
{
for (int count2 = 0; count2 < n; count2 = count2 + 2)
{
System.out.println(count, count2);
}
}
The outer loop will be executed n times. The inner loop will be executed (n+1)/2 times. Therefore, the growth function for the code fragment is n*((n+1)/2) = (n2 + n)/ 2. That is order n2.
You might also like to view...
In Alice, messages that produce a behavior are called ____.
A. routines B. methods C. procedures D. actions
Which of the following fire extinguisher types is used for wood and paper fires?
A) Class A B) Class B C) Class C D) Class D
Write the commands to assign the unique lines in the file names to the shell variable namelist.
What will be an ideal response?
Explain why aggregation is not used for IPv4 addresses on Internet routers.
What will be an ideal response?