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?

What do you call someone who asks many questions?

Unable to supress ligatures in headings which are set in Caps

What's the in-universe reasoning behind sorcerers needing material components?

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

Is it inappropriate for a student to attend their mentor's dissertation defense?

Why didn't Miles's spider sense work before?

Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?

Could the museum Saturn V's be refitted for one more flight?

One verb to replace 'be a member of' a club

How badly should I try to prevent a user from XSSing themselves?

Short story with a alien planet, government officials must wear exploding medallions

What killed these X2 caps?

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures

I would say: "You are another teacher", but she is a woman and I am a man

Can I run a new neutral wire to repair a broken circuit?

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

Is it possible to create a QR code using text?

What is the idiomatic way to say "clothing fits"?

Do UK voters know if their MP will be the Speaker of the House?

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"

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

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

Assassin's bullet with mercury

Personal Teleportation: From Rags to Riches



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?













6















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

















  • 1





    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
















6















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

















  • 1





    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














6












6








6


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

612




612







  • 1





    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













  • 1





    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








1




1





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


















4















"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









        4















        "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















        4















        "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













        4












        4








        4








        "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 4 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 28 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

                                बाताम इन्हें भी देखें सन्दर्भ दिक्चालन सूची1°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.033331°05′00″N 104°02′0″E / 1.08333°N 104.03333°E / 1.08333; 104.03333

                                Why is the 'in' operator throwing an error with a string literal instead of logging false?Why can't I use switch statement on a String?Python join: why is it string.join(list) instead of list.join(string)?Multiline String Literal in C#Why does comparing strings using either '==' or 'is' sometimes produce a different result?How to initialize an array's length in javascript?How can I print literal curly-brace characters in python string and also use .format on it?Why does ++[[]][+[]]+[+[]] return the string “10”?Why is char[] preferred over String for passwords?Why does this code using random strings print “hello world”?jQuery.inArray(), how to use it right?

                                How can we generalize the fact of finite dimensional vector space to an infinte dimensional case?$k[x]$-module and cyclic module over a finite dimensional vector spaceSubspace of a finite dimensional space is finite dimensionalIf V is an infinite-dimensional vector space, and S is an infinite-dimensional subspace of V, must the dimension of V/S be finite? ExplainWhy is an infinite dimensional space so different than a finite dimensional one?base for finite dimensional vector space is not infinite dimensional vector space?Any finite-dimensional vector space is the dual space of anotherHaving Trouble Understanding Meaning Of A Finite-Dimensional Vector SpaceProve that “Every subspaces of a finite-dimensional vector space is finite-dimensional”Ring as a finite dimensional Vector space over a field KQuestion regarding basis and dimension