retagged by
313 views

1 Answer

0 votes
0 votes

your code looks like

for (p=1 to n*n)
    for(q=1 to p)
            sum=sum-1

time complexity of the above snippet will be equal to number of times  "sum=sum-1" runs.
p q
1 1
2 2
3 3
...... .....
n*n n*n

$T\left ( n \right )=1+2+3+...n^{2}=\left ( n^{2}*\left ( n^{2}+1 \right ) \right )/2$=O$\left ( n^{4} \right )$

edited by

Related questions

393
views
1 answers
0 votes
Atul Verma12 asked Jan 6, 2017
393 views
Let S be a unsorted array of n integers. Let t(n) denote the time taken for the most efficient algorithm to determined if there are two elements with sum less than 10 in S. ... t(n) < n2n2t(n) = (n2)0(n^2)I think 5th let's dicuss algo?
465
views
2 answers
0 votes
Shivangi Verma asked Dec 23, 2016
465 views
What is the time complexity to count the number of leaf nodes in a tree? I am getting O(nlogn) but answer is O(n) please anybody explain in detail
586
views
1 answers
0 votes
Shivangi Verma asked Dec 23, 2016
586 views
Is longest common palindromic subsequence a part of GATE syllabus?
344
views
2 answers
2 votes
Atul Verma12 asked Sep 19, 2016
344 views
ADA
Arrange them in asc order of growth rate?1/100,1/n,logn/n>When we take log in this question to compare we get -log100,-logn.log(logn)-logn.Here less negative no will have high growth rate or negat(quantity) will matter?PLZ Explain