When something is Big O, does it mean that it is exactly the result of Big O?











up vote
0
down vote

favorite












When we say a method has the time complexity of O(n^2) is it meant in the same way as in 10^2 = 100 or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?










share|improve this question






















  • Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
    – Mitchel Paulin
    Nov 10 at 16:01










  • Why not look it up in your favourite source of information?
    – n.m.
    Nov 10 at 16:08






  • 2




    I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
    – user7722505
    Nov 10 at 16:10








  • 3




    Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
    – Zabuza
    Nov 10 at 16:39












  • @LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the forall operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
    – Zabuza
    Nov 10 at 16:54

















up vote
0
down vote

favorite












When we say a method has the time complexity of O(n^2) is it meant in the same way as in 10^2 = 100 or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?










share|improve this question






















  • Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
    – Mitchel Paulin
    Nov 10 at 16:01










  • Why not look it up in your favourite source of information?
    – n.m.
    Nov 10 at 16:08






  • 2




    I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
    – user7722505
    Nov 10 at 16:10








  • 3




    Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
    – Zabuza
    Nov 10 at 16:39












  • @LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the forall operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
    – Zabuza
    Nov 10 at 16:54















up vote
0
down vote

favorite









up vote
0
down vote

favorite











When we say a method has the time complexity of O(n^2) is it meant in the same way as in 10^2 = 100 or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?










share|improve this question













When we say a method has the time complexity of O(n^2) is it meant in the same way as in 10^2 = 100 or does it mean that the method is at max or closest to that notation? I am really confused on how to undertand Big O. I remember something called upper bound, would that mean at max?







algorithm big-o






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 15:56







user7722505



















  • Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
    – Mitchel Paulin
    Nov 10 at 16:01










  • Why not look it up in your favourite source of information?
    – n.m.
    Nov 10 at 16:08






  • 2




    I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
    – user7722505
    Nov 10 at 16:10








  • 3




    Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
    – Zabuza
    Nov 10 at 16:39












  • @LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the forall operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
    – Zabuza
    Nov 10 at 16:54




















  • Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
    – Mitchel Paulin
    Nov 10 at 16:01










  • Why not look it up in your favourite source of information?
    – n.m.
    Nov 10 at 16:08






  • 2




    I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
    – user7722505
    Nov 10 at 16:10








  • 3




    Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
    – Zabuza
    Nov 10 at 16:39












  • @LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the forall operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
    – Zabuza
    Nov 10 at 16:54


















Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01




Upperbound can be thought of as a max. Its a way to look at the worst case running time complexity.
– Mitchel Paulin
Nov 10 at 16:01












Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08




Why not look it up in your favourite source of information?
– n.m.
Nov 10 at 16:08




2




2




I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10






I already looked there, and didn't get it. Wikipedia is actually my least favourite source, since I find that they complicate things very much.
– user7722505
Nov 10 at 16:10






3




3




Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39






Actually, the Wikipedia explanation is pretty decent if you carefully read through it and take a look at the illustrations. Let me write an answer summarizing what Wikipedia explains.
– Zabuza
Nov 10 at 16:39














@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the forall operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
– Zabuza
Nov 10 at 16:54






@LasseVågsætherKarlsen All of the notions are worst case in a sense that they must fulfill the forall operator in the definition. So a single bad execution forces the complexity class already. Big-O means that the function isn't worse (wrt to asymptotic complexity). Big-Omega means it isn't better than. Theta means its in the same complexity class.
– Zabuza
Nov 10 at 16:54














2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Explanation



If a method f is inside O(g), with g being another function, it means that at some point (exist some n_0 such that for all n > n_0) the function f will always output a smaller value than g for that point. However, g is allowed to have an arbitrary constant k. So f(n) <= k * g(n) for all n above some n_0. So f is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.



We say f is asymptotically bounded by g. Asymptotically means that we do not care how f behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0.





Illustration



An illustration would be this:



enter image description here



The blue function is k * g with some constant k, the red one is f. We see that f is greater at first, but then, starting at x_0, it will always be smaller than k * g. Thus f in O(g).





Definition



Mathematically, this can be expressed by



enter image description here



which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0 on, the function f must be smaller than k * g for all inputs. k is allowed to be some constant.



Both images are taken from Wikipedia.





Examples



Here are a couple of examples to familiarize with the definition:





  • n is in O(n) (trivially)


  • n is in O(n^2) (trivially)


  • 5n is in O(n^2) (starting from n_0 = 5)


  • 25n^2 is in O(n^2) (taking k = 25 or greater)


  • 2n^2 + 4n + 6 is in O(n^2) (take k = 3, starting from n_0 = 5)




Notes



Actually,O(g) is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g).



So, although some authors write f = O(g), it is actually wrong and should be f in O(g).



There are also other, similar, sets, which only differ in the direction of the bound:




  • Big-O: less equals <=

  • Small-o: less <

  • Big-Omega: greater equals >=

  • Small-omega: greater >

  • Theta: Big-O and Big-Omega at the same time (equals)






share|improve this answer






























    up vote
    3
    down vote













    If means that the running time is bounded above by N².



    More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.



    For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240689%2fwhen-something-is-big-o-does-it-mean-that-it-is-exactly-the-result-of-big-o%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown
























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      Explanation



      If a method f is inside O(g), with g being another function, it means that at some point (exist some n_0 such that for all n > n_0) the function f will always output a smaller value than g for that point. However, g is allowed to have an arbitrary constant k. So f(n) <= k * g(n) for all n above some n_0. So f is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.



      We say f is asymptotically bounded by g. Asymptotically means that we do not care how f behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0.





      Illustration



      An illustration would be this:



      enter image description here



      The blue function is k * g with some constant k, the red one is f. We see that f is greater at first, but then, starting at x_0, it will always be smaller than k * g. Thus f in O(g).





      Definition



      Mathematically, this can be expressed by



      enter image description here



      which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0 on, the function f must be smaller than k * g for all inputs. k is allowed to be some constant.



      Both images are taken from Wikipedia.





      Examples



      Here are a couple of examples to familiarize with the definition:





      • n is in O(n) (trivially)


      • n is in O(n^2) (trivially)


      • 5n is in O(n^2) (starting from n_0 = 5)


      • 25n^2 is in O(n^2) (taking k = 25 or greater)


      • 2n^2 + 4n + 6 is in O(n^2) (take k = 3, starting from n_0 = 5)




      Notes



      Actually,O(g) is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g).



      So, although some authors write f = O(g), it is actually wrong and should be f in O(g).



      There are also other, similar, sets, which only differ in the direction of the bound:




      • Big-O: less equals <=

      • Small-o: less <

      • Big-Omega: greater equals >=

      • Small-omega: greater >

      • Theta: Big-O and Big-Omega at the same time (equals)






      share|improve this answer



























        up vote
        1
        down vote



        accepted










        Explanation



        If a method f is inside O(g), with g being another function, it means that at some point (exist some n_0 such that for all n > n_0) the function f will always output a smaller value than g for that point. However, g is allowed to have an arbitrary constant k. So f(n) <= k * g(n) for all n above some n_0. So f is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.



        We say f is asymptotically bounded by g. Asymptotically means that we do not care how f behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0.





        Illustration



        An illustration would be this:



        enter image description here



        The blue function is k * g with some constant k, the red one is f. We see that f is greater at first, but then, starting at x_0, it will always be smaller than k * g. Thus f in O(g).





        Definition



        Mathematically, this can be expressed by



        enter image description here



        which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0 on, the function f must be smaller than k * g for all inputs. k is allowed to be some constant.



        Both images are taken from Wikipedia.





        Examples



        Here are a couple of examples to familiarize with the definition:





        • n is in O(n) (trivially)


        • n is in O(n^2) (trivially)


        • 5n is in O(n^2) (starting from n_0 = 5)


        • 25n^2 is in O(n^2) (taking k = 25 or greater)


        • 2n^2 + 4n + 6 is in O(n^2) (take k = 3, starting from n_0 = 5)




        Notes



        Actually,O(g) is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g).



        So, although some authors write f = O(g), it is actually wrong and should be f in O(g).



        There are also other, similar, sets, which only differ in the direction of the bound:




        • Big-O: less equals <=

        • Small-o: less <

        • Big-Omega: greater equals >=

        • Small-omega: greater >

        • Theta: Big-O and Big-Omega at the same time (equals)






        share|improve this answer

























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Explanation



          If a method f is inside O(g), with g being another function, it means that at some point (exist some n_0 such that for all n > n_0) the function f will always output a smaller value than g for that point. However, g is allowed to have an arbitrary constant k. So f(n) <= k * g(n) for all n above some n_0. So f is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.



          We say f is asymptotically bounded by g. Asymptotically means that we do not care how f behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0.





          Illustration



          An illustration would be this:



          enter image description here



          The blue function is k * g with some constant k, the red one is f. We see that f is greater at first, but then, starting at x_0, it will always be smaller than k * g. Thus f in O(g).





          Definition



          Mathematically, this can be expressed by



          enter image description here



          which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0 on, the function f must be smaller than k * g for all inputs. k is allowed to be some constant.



          Both images are taken from Wikipedia.





          Examples



          Here are a couple of examples to familiarize with the definition:





          • n is in O(n) (trivially)


          • n is in O(n^2) (trivially)


          • 5n is in O(n^2) (starting from n_0 = 5)


          • 25n^2 is in O(n^2) (taking k = 25 or greater)


          • 2n^2 + 4n + 6 is in O(n^2) (take k = 3, starting from n_0 = 5)




          Notes



          Actually,O(g) is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g).



          So, although some authors write f = O(g), it is actually wrong and should be f in O(g).



          There are also other, similar, sets, which only differ in the direction of the bound:




          • Big-O: less equals <=

          • Small-o: less <

          • Big-Omega: greater equals >=

          • Small-omega: greater >

          • Theta: Big-O and Big-Omega at the same time (equals)






          share|improve this answer














          Explanation



          If a method f is inside O(g), with g being another function, it means that at some point (exist some n_0 such that for all n > n_0) the function f will always output a smaller value than g for that point. However, g is allowed to have an arbitrary constant k. So f(n) <= k * g(n) for all n above some n_0. So f is allowed to first be bigger, if it then starts to be smaller and keeps being smaller.



          We say f is asymptotically bounded by g. Asymptotically means that we do not care how f behaves in the beginning. Only what it will do when approaching infinity. So we discard all inputs below n_0.





          Illustration



          An illustration would be this:



          enter image description here



          The blue function is k * g with some constant k, the red one is f. We see that f is greater at first, but then, starting at x_0, it will always be smaller than k * g. Thus f in O(g).





          Definition



          Mathematically, this can be expressed by



          enter image description here



          which is the usual definition of Big-O. From the explanation above, the definition should be clear. It says that from a certain n_0 on, the function f must be smaller than k * g for all inputs. k is allowed to be some constant.



          Both images are taken from Wikipedia.





          Examples



          Here are a couple of examples to familiarize with the definition:





          • n is in O(n) (trivially)


          • n is in O(n^2) (trivially)


          • 5n is in O(n^2) (starting from n_0 = 5)


          • 25n^2 is in O(n^2) (taking k = 25 or greater)


          • 2n^2 + 4n + 6 is in O(n^2) (take k = 3, starting from n_0 = 5)




          Notes



          Actually,O(g) is a set in the mathematical sense. It contains all functions with the above mentioned property (which are asymptotically bounded by g).



          So, although some authors write f = O(g), it is actually wrong and should be f in O(g).



          There are also other, similar, sets, which only differ in the direction of the bound:




          • Big-O: less equals <=

          • Small-o: less <

          • Big-Omega: greater equals >=

          • Small-omega: greater >

          • Theta: Big-O and Big-Omega at the same time (equals)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 10 at 17:03

























          answered Nov 10 at 16:39









          Zabuza

          11k52538




          11k52538
























              up vote
              3
              down vote













              If means that the running time is bounded above by N².



              More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.



              For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.






              share|improve this answer

























                up vote
                3
                down vote













                If means that the running time is bounded above by N².



                More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.



                For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.






                share|improve this answer























                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  If means that the running time is bounded above by N².



                  More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.



                  For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.






                  share|improve this answer












                  If means that the running time is bounded above by N².



                  More precisely, T(N) < C.N², where C is some constant, and the inequality is true as of a certain N*.



                  For example, 2N²+4N+6 = O(N²), because 2N²+4N+6 < 3N² for all N>5.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 10 at 16:01









                  Yves Daoust

                  36k72558




                  36k72558






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240689%2fwhen-something-is-big-o-does-it-mean-that-it-is-exactly-the-result-of-big-o%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Florida Star v. B. J. F.

                      Error while running script in elastic search , gateway timeout

                      Adding quotations to stringified JSON object values