When (not how or why) to calculate Big O of an algorithmBig O, how do you calculate/approximate it?How do I check if an array includes an object in JavaScript?What is the best algorithm for an overridden System.Object.GetHashCode?What is a plain English explanation of “Big O” notation?Do you use Big-O complexity evaluation in the 'real world'?Ukkonen's suffix tree algorithm in plain EnglishImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionHow to find time complexity of an algorithmHow to pair socks from a pile efficiently?What is the optimal algorithm for the game 2048?

Does the Idaho Potato Commission associate potato skins with healthy eating?

Why can't we play rap on piano?

Unable to supress ligatures in headings which are set in Caps

What does “the session was packed” mean in this context?

Mathematica command that allows it to read my intentions

Is "remove commented out code" correct English?

When (not how or why) to calculate Big O of an algorithm

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

How to prevent "they're falling in love" trope

Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?

Which is the best way to check return result?

How writing a dominant 7 sus4 chord in RNA ( Vsus7 chord in the 1st inversion)

In 'Revenger,' what does 'cove' come from?

How to tell a function to use the default argument values?

Unlock My Phone! February 2018

Bullying boss launched a smear campaign and made me unemployable

How can saying a song's name be a copyright violation?

Apex Framework / library for consuming REST services

Can a virus destroy the BIOS of a modern computer?

What killed these X2 caps?

Avoiding the "not like other girls" trope?

Why doesn't using multiple commands with a || or && conditional work?

What historical events would have to change in order to make 19th century "steampunk" technology possible?

Method Does Not Exist error message



When (not how or why) to calculate Big O of an algorithm


Big O, how do you calculate/approximate it?How do I check if an array includes an object in JavaScript?What is the best algorithm for an overridden System.Object.GetHashCode?What is a plain English explanation of “Big O” notation?Do you use Big-O complexity evaluation in the 'real world'?Ukkonen's suffix tree algorithm in plain EnglishImage Processing: Algorithm Improvement for 'Coca-Cola Can' RecognitionHow to find time complexity of an algorithmHow to pair socks from a pile efficiently?What is the optimal algorithm for the game 2048?













7















I was asked this question in an interview recently and was curious as to what others thought.



"When should you calculate Big O?"



Most sites/books talk about HOW to calc Big O but not actually when you should do it. I'm an entry level developer and I have minimal experience so I'm not sure if I'm thinking on the right track. My thinking is you would have a target Big O to work towards, develop the algorithm then calculate the Big O. Then try to refactor the algorithm for efficiency.



My question then becomes is this what actually happens in industry or am I far off?










share|improve this question

















  • 2





    You should understand the performance of every single method you write. If it takes a variable-sized input, and the complexity isn't obvious to you, then you should calculate it as part of this understanding.

    – Matt Timmermans
    5 hours ago
















7















I was asked this question in an interview recently and was curious as to what others thought.



"When should you calculate Big O?"



Most sites/books talk about HOW to calc Big O but not actually when you should do it. I'm an entry level developer and I have minimal experience so I'm not sure if I'm thinking on the right track. My thinking is you would have a target Big O to work towards, develop the algorithm then calculate the Big O. Then try to refactor the algorithm for efficiency.



My question then becomes is this what actually happens in industry or am I far off?










share|improve this question

















  • 2





    You should understand the performance of every single method you write. If it takes a variable-sized input, and the complexity isn't obvious to you, then you should calculate it as part of this understanding.

    – Matt Timmermans
    5 hours ago














7












7








7


1






I was asked this question in an interview recently and was curious as to what others thought.



"When should you calculate Big O?"



Most sites/books talk about HOW to calc Big O but not actually when you should do it. I'm an entry level developer and I have minimal experience so I'm not sure if I'm thinking on the right track. My thinking is you would have a target Big O to work towards, develop the algorithm then calculate the Big O. Then try to refactor the algorithm for efficiency.



My question then becomes is this what actually happens in industry or am I far off?










share|improve this question














I was asked this question in an interview recently and was curious as to what others thought.



"When should you calculate Big O?"



Most sites/books talk about HOW to calc Big O but not actually when you should do it. I'm an entry level developer and I have minimal experience so I'm not sure if I'm thinking on the right track. My thinking is you would have a target Big O to work towards, develop the algorithm then calculate the Big O. Then try to refactor the algorithm for efficiency.



My question then becomes is this what actually happens in industry or am I far off?







algorithm big-o






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 5 hours ago









Brian PhairBrian Phair

662




662







  • 2





    You should understand the performance of every single method you write. If it takes a variable-sized input, and the complexity isn't obvious to you, then you should calculate it as part of this understanding.

    – Matt Timmermans
    5 hours ago













  • 2





    You should understand the performance of every single method you write. If it takes a variable-sized input, and the complexity isn't obvious to you, then you should calculate it as part of this understanding.

    – Matt Timmermans
    5 hours ago








2




2





You should understand the performance of every single method you write. If it takes a variable-sized input, and the complexity isn't obvious to you, then you should calculate it as part of this understanding.

– Matt Timmermans
5 hours ago






You should understand the performance of every single method you write. If it takes a variable-sized input, and the complexity isn't obvious to you, then you should calculate it as part of this understanding.

– Matt Timmermans
5 hours ago













5 Answers
5






active

oldest

votes


















6















"When should you calculate Big O?"




When you care about the Time Complexity of the algorithm.



When do I care?



When you need to make your algorithm to be able to scale, meaning that it's expected to have big datasets as input to your algorithm (e.g. number of points and number of dimensions in a nearest neighbor algorithm).



Most notably, when you want to compare algorithms!



You are asked to do a task, for which several algorithms can be applied to. Which one do you choose? You compare the Space, Time and implementation complexities of them, and choose the one that best fits your needs.






share|improve this answer




















  • 2





    Intersting. I didn't think about incorporating scalability into the answer. I'll make sure to consider that going forward. Thanks!

    – Brian Phair
    5 hours ago






  • 1





    You are welcome @BrianPhair, check my edit about using Time complexity as a powerful semaphore to compare algorithms. Good luck with your interview, good question.

    – gsamaras
    5 hours ago


















0














It represents the upper bound.
Big-oh is the most useful because represents the worst-case behavior. So, it guarantees that the program will terminate within a certain time period, it may stop earlier, but never later.



It gives the worst time complexity or maximum time require to execute the algorithm






share|improve this answer


















  • 4





    Strictly speaking, this is not correct. Big-O denotes an asymptotic upper bound, but it can be applied to any function, not just worst-case performance. In fact, it's not unusual to apply it to average/expected-case performance. (That said, it's true that people often use big-O to mean the big-Θ of the worst case.)

    – ruakh
    5 hours ago











  • ya...it's right

    – RS Patel
    5 hours ago


















0














Big O or asymptotic notations allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases.



So whenever you need to analyse your algorithm's behavior with respect to growth of the input, you will calculate this. Let me give you an example -



Suppose you need to query over 1 billion data. So you wrote a linear search algorithm. So is it okay? How would you know? You will calculate Big-o. It's O(n) for linear search. So in worst case it would execute 1 billion instruction to query. If your machine executes 10^7 instruction per second(let's assume), then it would take 100 seconds. So you see - you are getting an runtime analysis in terms of growth of the input.






share|improve this answer






























    0














    When we are solving an algorithmic problem we want to test the algorithm irrespective of hardware where we are running the algorithm. So we have certain asymptotic notation using which we can define the time and space complexities of our algorithm.



    1. Theta-Notation: Used for defining average case complexity as it bounds the function from top and bottom


    2. Omega-Notation: Bounds the function from below. It is used for best-time complexity


    3. Big-O Notation: This is important as it tells about worst-case complexity and it bounds the function from top.


    Now I think the answer to Why BIG-O is calculated is that using it we can get a fair idea that how bad our algorithm can perform as the size of input increases. And If we can optimize our algorithm for worst case then average and best case will take care for themselves.






    share|improve this answer






























      0














      I assume that you want to ask "when should I calculate time complexity?", just to avoid technicalities about Theta, Omega and Big-O.



      Right attitude is to guess it almost always. Notable exceptions include piece of code you want to run just once and you are sure that it will never receive bigger input.



      The emphasis on guess is because it does not matter that much whether complexity is constant or logarithmic. There is also a little difference between O(n^2) and O(n^2 log n) or between O(n^3) and O(n^4). But there is a big difference between constant and linear.



      The main goal of the guess, is the answer to the question: "What happens if I get 10 times larger input?". If complexity is constant, nothing happens (in theory at least). If complexity is linear, you will get 10 times larger running time. If complexity is quadratic or bigger, you start to have problems.
      Secondary goal of the guess is the answer to question: 'What is the biggest input I can handle?". Again quadratic will get you up to 10000 at most. O(2^n) ends around 25.



      This might sound scary and time consuming, but in practice, getting time complexity of the code is rather trivial, since most of the things are either constant, logarithmic or linear.






      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',
        autoActivateHeartbeat: false,
        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%2f55500051%2fwhen-not-how-or-why-to-calculate-big-o-of-an-algorithm%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        6















        "When should you calculate Big O?"




        When you care about the Time Complexity of the algorithm.



        When do I care?



        When you need to make your algorithm to be able to scale, meaning that it's expected to have big datasets as input to your algorithm (e.g. number of points and number of dimensions in a nearest neighbor algorithm).



        Most notably, when you want to compare algorithms!



        You are asked to do a task, for which several algorithms can be applied to. Which one do you choose? You compare the Space, Time and implementation complexities of them, and choose the one that best fits your needs.






        share|improve this answer




















        • 2





          Intersting. I didn't think about incorporating scalability into the answer. I'll make sure to consider that going forward. Thanks!

          – Brian Phair
          5 hours ago






        • 1





          You are welcome @BrianPhair, check my edit about using Time complexity as a powerful semaphore to compare algorithms. Good luck with your interview, good question.

          – gsamaras
          5 hours ago















        6















        "When should you calculate Big O?"




        When you care about the Time Complexity of the algorithm.



        When do I care?



        When you need to make your algorithm to be able to scale, meaning that it's expected to have big datasets as input to your algorithm (e.g. number of points and number of dimensions in a nearest neighbor algorithm).



        Most notably, when you want to compare algorithms!



        You are asked to do a task, for which several algorithms can be applied to. Which one do you choose? You compare the Space, Time and implementation complexities of them, and choose the one that best fits your needs.






        share|improve this answer




















        • 2





          Intersting. I didn't think about incorporating scalability into the answer. I'll make sure to consider that going forward. Thanks!

          – Brian Phair
          5 hours ago






        • 1





          You are welcome @BrianPhair, check my edit about using Time complexity as a powerful semaphore to compare algorithms. Good luck with your interview, good question.

          – gsamaras
          5 hours ago













        6












        6








        6








        "When should you calculate Big O?"




        When you care about the Time Complexity of the algorithm.



        When do I care?



        When you need to make your algorithm to be able to scale, meaning that it's expected to have big datasets as input to your algorithm (e.g. number of points and number of dimensions in a nearest neighbor algorithm).



        Most notably, when you want to compare algorithms!



        You are asked to do a task, for which several algorithms can be applied to. Which one do you choose? You compare the Space, Time and implementation complexities of them, and choose the one that best fits your needs.






        share|improve this answer
















        "When should you calculate Big O?"




        When you care about the Time Complexity of the algorithm.



        When do I care?



        When you need to make your algorithm to be able to scale, meaning that it's expected to have big datasets as input to your algorithm (e.g. number of points and number of dimensions in a nearest neighbor algorithm).



        Most notably, when you want to compare algorithms!



        You are asked to do a task, for which several algorithms can be applied to. Which one do you choose? You compare the Space, Time and implementation complexities of them, and choose the one that best fits your needs.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 5 hours ago

























        answered 5 hours ago









        gsamarasgsamaras

        52.3k25107193




        52.3k25107193







        • 2





          Intersting. I didn't think about incorporating scalability into the answer. I'll make sure to consider that going forward. Thanks!

          – Brian Phair
          5 hours ago






        • 1





          You are welcome @BrianPhair, check my edit about using Time complexity as a powerful semaphore to compare algorithms. Good luck with your interview, good question.

          – gsamaras
          5 hours ago












        • 2





          Intersting. I didn't think about incorporating scalability into the answer. I'll make sure to consider that going forward. Thanks!

          – Brian Phair
          5 hours ago






        • 1





          You are welcome @BrianPhair, check my edit about using Time complexity as a powerful semaphore to compare algorithms. Good luck with your interview, good question.

          – gsamaras
          5 hours ago







        2




        2





        Intersting. I didn't think about incorporating scalability into the answer. I'll make sure to consider that going forward. Thanks!

        – Brian Phair
        5 hours ago





        Intersting. I didn't think about incorporating scalability into the answer. I'll make sure to consider that going forward. Thanks!

        – Brian Phair
        5 hours ago




        1




        1





        You are welcome @BrianPhair, check my edit about using Time complexity as a powerful semaphore to compare algorithms. Good luck with your interview, good question.

        – gsamaras
        5 hours ago





        You are welcome @BrianPhair, check my edit about using Time complexity as a powerful semaphore to compare algorithms. Good luck with your interview, good question.

        – gsamaras
        5 hours ago













        0














        It represents the upper bound.
        Big-oh is the most useful because represents the worst-case behavior. So, it guarantees that the program will terminate within a certain time period, it may stop earlier, but never later.



        It gives the worst time complexity or maximum time require to execute the algorithm






        share|improve this answer


















        • 4





          Strictly speaking, this is not correct. Big-O denotes an asymptotic upper bound, but it can be applied to any function, not just worst-case performance. In fact, it's not unusual to apply it to average/expected-case performance. (That said, it's true that people often use big-O to mean the big-Θ of the worst case.)

          – ruakh
          5 hours ago











        • ya...it's right

          – RS Patel
          5 hours ago















        0














        It represents the upper bound.
        Big-oh is the most useful because represents the worst-case behavior. So, it guarantees that the program will terminate within a certain time period, it may stop earlier, but never later.



        It gives the worst time complexity or maximum time require to execute the algorithm






        share|improve this answer


















        • 4





          Strictly speaking, this is not correct. Big-O denotes an asymptotic upper bound, but it can be applied to any function, not just worst-case performance. In fact, it's not unusual to apply it to average/expected-case performance. (That said, it's true that people often use big-O to mean the big-Θ of the worst case.)

          – ruakh
          5 hours ago











        • ya...it's right

          – RS Patel
          5 hours ago













        0












        0








        0







        It represents the upper bound.
        Big-oh is the most useful because represents the worst-case behavior. So, it guarantees that the program will terminate within a certain time period, it may stop earlier, but never later.



        It gives the worst time complexity or maximum time require to execute the algorithm






        share|improve this answer













        It represents the upper bound.
        Big-oh is the most useful because represents the worst-case behavior. So, it guarantees that the program will terminate within a certain time period, it may stop earlier, but never later.



        It gives the worst time complexity or maximum time require to execute the algorithm







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 5 hours ago









        RS PatelRS Patel

        17714




        17714







        • 4





          Strictly speaking, this is not correct. Big-O denotes an asymptotic upper bound, but it can be applied to any function, not just worst-case performance. In fact, it's not unusual to apply it to average/expected-case performance. (That said, it's true that people often use big-O to mean the big-Θ of the worst case.)

          – ruakh
          5 hours ago











        • ya...it's right

          – RS Patel
          5 hours ago












        • 4





          Strictly speaking, this is not correct. Big-O denotes an asymptotic upper bound, but it can be applied to any function, not just worst-case performance. In fact, it's not unusual to apply it to average/expected-case performance. (That said, it's true that people often use big-O to mean the big-Θ of the worst case.)

          – ruakh
          5 hours ago











        • ya...it's right

          – RS Patel
          5 hours ago







        4




        4





        Strictly speaking, this is not correct. Big-O denotes an asymptotic upper bound, but it can be applied to any function, not just worst-case performance. In fact, it's not unusual to apply it to average/expected-case performance. (That said, it's true that people often use big-O to mean the big-Θ of the worst case.)

        – ruakh
        5 hours ago





        Strictly speaking, this is not correct. Big-O denotes an asymptotic upper bound, but it can be applied to any function, not just worst-case performance. In fact, it's not unusual to apply it to average/expected-case performance. (That said, it's true that people often use big-O to mean the big-Θ of the worst case.)

        – ruakh
        5 hours ago













        ya...it's right

        – RS Patel
        5 hours ago





        ya...it's right

        – RS Patel
        5 hours ago











        0














        Big O or asymptotic notations allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases.



        So whenever you need to analyse your algorithm's behavior with respect to growth of the input, you will calculate this. Let me give you an example -



        Suppose you need to query over 1 billion data. So you wrote a linear search algorithm. So is it okay? How would you know? You will calculate Big-o. It's O(n) for linear search. So in worst case it would execute 1 billion instruction to query. If your machine executes 10^7 instruction per second(let's assume), then it would take 100 seconds. So you see - you are getting an runtime analysis in terms of growth of the input.






        share|improve this answer



























          0














          Big O or asymptotic notations allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases.



          So whenever you need to analyse your algorithm's behavior with respect to growth of the input, you will calculate this. Let me give you an example -



          Suppose you need to query over 1 billion data. So you wrote a linear search algorithm. So is it okay? How would you know? You will calculate Big-o. It's O(n) for linear search. So in worst case it would execute 1 billion instruction to query. If your machine executes 10^7 instruction per second(let's assume), then it would take 100 seconds. So you see - you are getting an runtime analysis in terms of growth of the input.






          share|improve this answer

























            0












            0








            0







            Big O or asymptotic notations allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases.



            So whenever you need to analyse your algorithm's behavior with respect to growth of the input, you will calculate this. Let me give you an example -



            Suppose you need to query over 1 billion data. So you wrote a linear search algorithm. So is it okay? How would you know? You will calculate Big-o. It's O(n) for linear search. So in worst case it would execute 1 billion instruction to query. If your machine executes 10^7 instruction per second(let's assume), then it would take 100 seconds. So you see - you are getting an runtime analysis in terms of growth of the input.






            share|improve this answer













            Big O or asymptotic notations allow us to analyze an algorithm's running time by identifying its behavior as the input size for the algorithm increases.



            So whenever you need to analyse your algorithm's behavior with respect to growth of the input, you will calculate this. Let me give you an example -



            Suppose you need to query over 1 billion data. So you wrote a linear search algorithm. So is it okay? How would you know? You will calculate Big-o. It's O(n) for linear search. So in worst case it would execute 1 billion instruction to query. If your machine executes 10^7 instruction per second(let's assume), then it would take 100 seconds. So you see - you are getting an runtime analysis in terms of growth of the input.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 5 hours ago









            Arnab RoyArnab Roy

            395314




            395314





















                0














                When we are solving an algorithmic problem we want to test the algorithm irrespective of hardware where we are running the algorithm. So we have certain asymptotic notation using which we can define the time and space complexities of our algorithm.



                1. Theta-Notation: Used for defining average case complexity as it bounds the function from top and bottom


                2. Omega-Notation: Bounds the function from below. It is used for best-time complexity


                3. Big-O Notation: This is important as it tells about worst-case complexity and it bounds the function from top.


                Now I think the answer to Why BIG-O is calculated is that using it we can get a fair idea that how bad our algorithm can perform as the size of input increases. And If we can optimize our algorithm for worst case then average and best case will take care for themselves.






                share|improve this answer



























                  0














                  When we are solving an algorithmic problem we want to test the algorithm irrespective of hardware where we are running the algorithm. So we have certain asymptotic notation using which we can define the time and space complexities of our algorithm.



                  1. Theta-Notation: Used for defining average case complexity as it bounds the function from top and bottom


                  2. Omega-Notation: Bounds the function from below. It is used for best-time complexity


                  3. Big-O Notation: This is important as it tells about worst-case complexity and it bounds the function from top.


                  Now I think the answer to Why BIG-O is calculated is that using it we can get a fair idea that how bad our algorithm can perform as the size of input increases. And If we can optimize our algorithm for worst case then average and best case will take care for themselves.






                  share|improve this answer

























                    0












                    0








                    0







                    When we are solving an algorithmic problem we want to test the algorithm irrespective of hardware where we are running the algorithm. So we have certain asymptotic notation using which we can define the time and space complexities of our algorithm.



                    1. Theta-Notation: Used for defining average case complexity as it bounds the function from top and bottom


                    2. Omega-Notation: Bounds the function from below. It is used for best-time complexity


                    3. Big-O Notation: This is important as it tells about worst-case complexity and it bounds the function from top.


                    Now I think the answer to Why BIG-O is calculated is that using it we can get a fair idea that how bad our algorithm can perform as the size of input increases. And If we can optimize our algorithm for worst case then average and best case will take care for themselves.






                    share|improve this answer













                    When we are solving an algorithmic problem we want to test the algorithm irrespective of hardware where we are running the algorithm. So we have certain asymptotic notation using which we can define the time and space complexities of our algorithm.



                    1. Theta-Notation: Used for defining average case complexity as it bounds the function from top and bottom


                    2. Omega-Notation: Bounds the function from below. It is used for best-time complexity


                    3. Big-O Notation: This is important as it tells about worst-case complexity and it bounds the function from top.


                    Now I think the answer to Why BIG-O is calculated is that using it we can get a fair idea that how bad our algorithm can perform as the size of input increases. And If we can optimize our algorithm for worst case then average and best case will take care for themselves.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered 5 hours ago









                    Yug SinghYug Singh

                    1,4552926




                    1,4552926





















                        0














                        I assume that you want to ask "when should I calculate time complexity?", just to avoid technicalities about Theta, Omega and Big-O.



                        Right attitude is to guess it almost always. Notable exceptions include piece of code you want to run just once and you are sure that it will never receive bigger input.



                        The emphasis on guess is because it does not matter that much whether complexity is constant or logarithmic. There is also a little difference between O(n^2) and O(n^2 log n) or between O(n^3) and O(n^4). But there is a big difference between constant and linear.



                        The main goal of the guess, is the answer to the question: "What happens if I get 10 times larger input?". If complexity is constant, nothing happens (in theory at least). If complexity is linear, you will get 10 times larger running time. If complexity is quadratic or bigger, you start to have problems.
                        Secondary goal of the guess is the answer to question: 'What is the biggest input I can handle?". Again quadratic will get you up to 10000 at most. O(2^n) ends around 25.



                        This might sound scary and time consuming, but in practice, getting time complexity of the code is rather trivial, since most of the things are either constant, logarithmic or linear.






                        share|improve this answer



























                          0














                          I assume that you want to ask "when should I calculate time complexity?", just to avoid technicalities about Theta, Omega and Big-O.



                          Right attitude is to guess it almost always. Notable exceptions include piece of code you want to run just once and you are sure that it will never receive bigger input.



                          The emphasis on guess is because it does not matter that much whether complexity is constant or logarithmic. There is also a little difference between O(n^2) and O(n^2 log n) or between O(n^3) and O(n^4). But there is a big difference between constant and linear.



                          The main goal of the guess, is the answer to the question: "What happens if I get 10 times larger input?". If complexity is constant, nothing happens (in theory at least). If complexity is linear, you will get 10 times larger running time. If complexity is quadratic or bigger, you start to have problems.
                          Secondary goal of the guess is the answer to question: 'What is the biggest input I can handle?". Again quadratic will get you up to 10000 at most. O(2^n) ends around 25.



                          This might sound scary and time consuming, but in practice, getting time complexity of the code is rather trivial, since most of the things are either constant, logarithmic or linear.






                          share|improve this answer

























                            0












                            0








                            0







                            I assume that you want to ask "when should I calculate time complexity?", just to avoid technicalities about Theta, Omega and Big-O.



                            Right attitude is to guess it almost always. Notable exceptions include piece of code you want to run just once and you are sure that it will never receive bigger input.



                            The emphasis on guess is because it does not matter that much whether complexity is constant or logarithmic. There is also a little difference between O(n^2) and O(n^2 log n) or between O(n^3) and O(n^4). But there is a big difference between constant and linear.



                            The main goal of the guess, is the answer to the question: "What happens if I get 10 times larger input?". If complexity is constant, nothing happens (in theory at least). If complexity is linear, you will get 10 times larger running time. If complexity is quadratic or bigger, you start to have problems.
                            Secondary goal of the guess is the answer to question: 'What is the biggest input I can handle?". Again quadratic will get you up to 10000 at most. O(2^n) ends around 25.



                            This might sound scary and time consuming, but in practice, getting time complexity of the code is rather trivial, since most of the things are either constant, logarithmic or linear.






                            share|improve this answer













                            I assume that you want to ask "when should I calculate time complexity?", just to avoid technicalities about Theta, Omega and Big-O.



                            Right attitude is to guess it almost always. Notable exceptions include piece of code you want to run just once and you are sure that it will never receive bigger input.



                            The emphasis on guess is because it does not matter that much whether complexity is constant or logarithmic. There is also a little difference between O(n^2) and O(n^2 log n) or between O(n^3) and O(n^4). But there is a big difference between constant and linear.



                            The main goal of the guess, is the answer to the question: "What happens if I get 10 times larger input?". If complexity is constant, nothing happens (in theory at least). If complexity is linear, you will get 10 times larger running time. If complexity is quadratic or bigger, you start to have problems.
                            Secondary goal of the guess is the answer to question: 'What is the biggest input I can handle?". Again quadratic will get you up to 10000 at most. O(2^n) ends around 25.



                            This might sound scary and time consuming, but in practice, getting time complexity of the code is rather trivial, since most of the things are either constant, logarithmic or linear.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered 44 mins ago









                            usamecusamec

                            1,2201119




                            1,2201119



























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55500051%2fwhen-not-how-or-why-to-calculate-big-o-of-an-algorithm%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

                                Best approach to update all entries in a list that is paginated?Best way to add items to a paginated listChoose Your Country: Best Usability approachUpdate list when a user is viewing the list without annoying themWhen would the best day to update your webpage be?What should happen when I add a Row to a paginated, sorted listShould I adopt infinite scrolling or classical pagination?How to show user that page objects automatically updateWhat is the best location to locate the comments section in a list pageBest way to combine filtering and selecting items in a listWhen one of two inputs must be updated to satisfy a consistency criteria, which should you update (if at all)?

                                Вунгтау (аеропорт) Загальні відомості | Див. також | Посилання | Навігаційне меню10°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.0833310°22′00″ пн. ш. 107°05′00″ сх. д. / 10.36667° пн. ш. 107.08333° сх. д. / 10.36667; 107.083337731608Vinh AirportVinh airport facelift improves serviceвиправивши або дописавши їївиправивши або дописавши їїр

                                Тонконіг бульбистий Зміст Опис | Поширення | Екологія | Господарське значення | Примітки | Див. також | Література | Джерела | Посилання | Навігаційне меню1114601320038-241116202404kew-435458Poa bulbosaЭлектронный каталог сосудистых растений Азиатской России [Електронний каталог судинних рослин Азіатської Росії]Малышев Л. Л. Дикие родичи культурных растений. Poa bulbosa L. - Мятлик луковичный. [Малишев Л. Л. Дикі родичи культурних рослин. Poa bulbosa L. - Тонконіг бульбистий.]Мятлик (POA) Сем. Злаки (Мятликовые) [Тонконіг (POA) Род. Злаки (Тонконогові)]Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Description from Flora of China) [Poa bulbosa Linnaeus, Sp. Pl. 1: 70. 1753. 鳞茎早熟禾 lin jing zao shu he (Опис від Флора Китаю)]Poa bulbosa L. – lipnice cibulkatá / lipnica cibulkatáPoa bulbosa в базі даних Poa bulbosa на сайті Poa bulbosa в базі даних «Global Biodiversity Information Facility» (GBIF)Poa bulbosa в базі даних «Euro + Med PlantBase» — інформаційному ресурсі для Євро-середземноморського розмаїття рослинPoa bulbosa L. на сайті «Плантариум»