wood burning stoves 2.0*
The moose likes Performance and the fly likes Time Complexity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Time Complexity" Watch "Time Complexity" New topic

Time Complexity

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 688

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 ?

The Only way to learn is ...........do!
Visit my blog http://inaved-momin.blogspot.com/
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41108
It's O(n ^2). Compared to n^2, n*log n is asymptotically irrelevant.

Ping & DNS - my free Android networking tools app
fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11160

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.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 688

thanks ..appreciate your input....

so conclusion is ..its O(n^2) ....
I agree. Here's the link: http://aspose.com/file-tools
subject: Time Complexity
Similar Threads
big O notation
Recent interview question - Find a pair in array whose sum is x.
What discipline of math do you use most often?
Big O
Computer Engineer Vs Certified/s