2 Replies - 2164 Views - Last Post: 19 January 2013 - 06:01 PM

#1 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Big-Oh analysis

Posted 19 January 2013 - 05:39 PM

Just a simple question. Is the following sample the equivalent of O(2)?

int i = 0;
int j = 0;

There are only two assignments, no loops, nested loops, comparisons or additions. It's basically O(1) + O(1), right?
Is This A Good Question/Topic? 0
  • +

Replies To: Big-Oh analysis

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,311
  • Joined: 21-June 11

Re: Big-Oh analysis

Posted 19 January 2013 - 05:44 PM

It's not really meaningful to speak of O(2) since constant factors do not matter in big-oh notation, so O(2) is the same thing as O(1). If a piece of code has constant running time, we say it's running time is in O(1) - no matter what the constant is.

PS: I've moved this thread to the Computer Science forum as it wasn't really about Java, but rather about big-oh notation.

This post has been edited by sepp2k: 19 January 2013 - 05:46 PM

Was This Post Helpful? 1
  • +
  • -

#3 iburres  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 05-September 12

Re: Big-Oh analysis

Posted 19 January 2013 - 06:01 PM

I didn't realize I posted in the Java forum. Sorry about that and thanks for that clearing that up for me.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1