Answer:
This is correct. And to remove the confusion, I am adding the meaning of the Pseudocode. You need to begin with the algo that you are working upon, and then you need it to phrase the algo with the words which are easy to be transcribed in the form of the computer instructions. Now you need to indent the instructions properly inside the loop or within the conditional clauses. And while doing this, you need to not use the words which are used in certain forms of computer language. However, IF and THEN and ELSE and ENDIF are very frequently used as pseudo-code. Hence, your answer is correct.
Explanation:
Please check the answer section.
Answer:
//Here is the for loop in C.
for(n=10;n>0;n--)
{
printf("count =%d \n",n);
}
Explanation:
Since C is a procedural programming language.Here if a loop that starts with n=10; It will run till n becomes 0. When n reaches to 0 then loop terminates otherwise it print the count of n.
// here is code in C++.
#include <bits/stdc++.h>
using namespace std;
// main function
int main()
{ // variables
int n;
// for loop that runs 10 times
// when n==0 then loop terminates
for(n=10;n>0;n--)
{
cout<<"count ="<<n<<endl;
}
return 0;
}
Output:
count =10
count =9
count =8
count =7
count =6
count =5
count =4
count =3
count =2
count =1
Kayla could use “save as” to rename the document.
Big-O notation is a way to describe a function that represents the n amount of times a program/function needs to be executed.
(I'm assuming that := is a typo and you mean just =, by the way)
In your case, you have two loops, nested within each other, and both loop to n (inclusive, meaning, that you loop for when i or j is equal to n), and both loops iterate by 1 each loop.
This means that both loops will therefore execute an n amount of times. Now, if the loops were NOT nested, our big-O would be O(2n), because 2 loops would run an n amount of times.
HOWEVER, since the j-loop is nested within i-loop, the j-loop executes every time the i-loop <span>ITERATES.
</span>
As previously mentioned, for every i-loop, there would be an n amount of executions. So if the i-loop is called an n amount of times by the j loop (which executes n times), the big-O notation would be O(n*n), or O(n^2).
(tl;dr) In basic, it is O(n^2) because the loops are nested, meaning that the i-loop would be called n times, and for each iteration, it would call the j-loop n times, resulting in n*n runs.
A way to verify this is to write and test program the above. I sometimes find it easier to wrap my head around concepts after testing them myself.