• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time Complexity

 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi All...

Suppose i have written a method like this


then what will be time complexity of my code...according to me it will be O(nlgn + n^2) ...is it correct ?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's O(n ^2). Compared to n^2, n*log n is asymptotically irrelevant.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in Big-O notation, you ignore all but the most significant term. so when you look at O(nlgn + n^2), the (n lg n) term grows so much slower than n^2, as n -> infinity, it really doesn't count for much. Therefore, you can safely ignore it.
 
naved momin
Ranch Hand
Posts: 692
Eclipse IDE Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks ..appreciate your input....


so conclusion is ..its O(n^2) ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic