Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Algorithm Analysis Question

 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 106
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

If I have a method which has two O(n) operations, then what would be Order of the method itself? Is it sill O(n)?

Thanks,
Pavan.
 
Mike Simmons
Ranch Hand
Posts: 3076
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the method just calls the two operations one after the other, then yes, the result is O(n).

If the method has loops or if statements, the result may be different. For example if it loops n times and calls one or more O(n) operations, the result is O(n^2).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic