• edited by
971 views

3 Answers

Best answer
3 3 votes

Counting the number of times the inner most loop gets executed equals, 

n-2 + n-3 + n-2 + ....1
+n-3 + n-2 + .... + 1
+
...
+ 3 + 2 + 1

= (n-2)(n-1)/2 + (n-3)(n-2)/2 + ... + 3*4/2

= (n2 - 3n + 2 + n2 - 5n + 6 + .... )/2

= O(n3) as there are n terms and n2 is the dominating term in each of them. 

• selected by
0 0 votes
This should be O(n^3) as for each iteration of outer loop inner loop runs O(n^2) time and outer loop runs O(n) time
Position:
Show:

Related questions

2 2 votes
1 1 answer
1.8k
1.8k views
I_am_winner asked Sep 6, 2018
1,752 views
It answer is given as A but according to me answer should be C.Please help
2 2 votes
1 answers 1 answer
670
670 views
Siramdas Vamshidhar asked Nov 25, 2014
670 views
Algorithm Power(n) Pre: n :: Integer, n 0 i = 1 while (i < n) print i i = i * 3 done
61 61 votes
5 answers 5 answers
25.4k
25.4k views
Arjun asked Feb 12, 2020
25,379 views
Consider a double hashing scheme in which the primary hash function is $h_1(k)= k \text{ mod } 23$, and the secondary hash function is $h_2(k)=1+(k \text{ mod } 19)$. Ass...
3 3 votes
1 1 answer
224
224 views
GO Classes asked Aug 31
224 views
The algorithm $\text{ALGSORT}$ sorts an array of distinct integers using comparisons.The function $\text{MININDEX(V,i,j)}$ returns the position of the smallest element in...