This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Algorithm Analysis Question  RSS feed

 
Pavan Kumar Dittakavi
Ranch Hand
Posts: 108
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: 3090
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).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!