120k views
3 votes
Consider the following pseudocode. How much time does the code take to execute? Express all answers in terms of the input variable n, using Big-Oh O( ) notation.void george(int n) {int m = n;while (m > 1){ for (int i = 1; i < m; i++) int S = 1; m = m/2; }}

1 Answer

3 votes

Answer:

Time the code takes to execute is O(n²)

Step-by-step explanation:

The code forms an arithmetic series using it two loops.

n+(n-1)+(n-2)+........+2+1

=n(n+1)/2

=O(n²)

User Rafsanjani
by
4.2k points