This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "Time Complexity" Watch "Time Complexity" New topic

Time Complexity

naved momin
Ranch Hand

Joined: Jul 03, 2011
Posts: 692

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) it correct ?

The Only way to learn is!
Visit my blog
Ulf Dittmer

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

Joined: Oct 02, 2003
Posts: 11955

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: 692

thanks ..appreciate your input....

so conclusion is ..its O(n^2) ....
I agree. Here's the link:
subject: Time Complexity
It's not a secret anymore!