This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Algorithm Analysis Question  RSS feed

 
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: 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).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!