Algorithm complexity with iterations. Is it logarithmic or exponential?Big O, how do you calculate/approximate it?Improve INSERT-per-second performance of SQLite?Time complexity of a recursive algorithmSpeed comparison with Project Euler: C vs Python vs Erlang vs HaskellWhat does the C ??!??! operator do?How to find time complexity of an algorithmThe time complexity of the leader-follower algorithm?How is the complexity of this algorithm logarithmic?Time complexity of iterative and recursive algorithmsCalculating the time complexity of recursive algorithm T(n) = T(k) + T(n-k)Why is the time complexity of this algorithm exponential?

Size of electromagnet needed to replicate Earth's magnetic field

Why must Chinese maps be obfuscated?

Get consecutive integer number ranges from list of int

Pre-plastic human skin alternative

Does Gita support doctrine of eternal samsara?

Apply MapThread to all but one variable

What makes accurate emulation of old systems a difficult task?

Aliens crash on Earth and go into stasis to wait for technology to fix their ship

Extension of 2-adic valuation to the real numbers

Multiple options vs single option UI

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

How to pronounce 'c++' in Spanish

Can someone publish a story that happened to you?

Solving polynominals equations (relationship of roots)

On The Origin of Dissonant Chords

Do I have an "anti-research" personality?

How can I practically buy stocks?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

What happens to Mjolnir (Thor's hammer) at the end of Endgame?

What's the polite way to say "I need to urinate"?

Is there really no use for MD5 anymore?

How to limit Drive Letters Windows assigns to new removable USB drives

How could Tony Stark make this in Endgame?

"Whatever a Russian does, they end up making the Kalashnikov gun"? Are there any similar proverbs in English?



Algorithm complexity with iterations. Is it logarithmic or exponential?


Big O, how do you calculate/approximate it?Improve INSERT-per-second performance of SQLite?Time complexity of a recursive algorithmSpeed comparison with Project Euler: C vs Python vs Erlang vs HaskellWhat does the C ??!??! operator do?How to find time complexity of an algorithmThe time complexity of the leader-follower algorithm?How is the complexity of this algorithm logarithmic?Time complexity of iterative and recursive algorithmsCalculating the time complexity of recursive algorithm T(n) = T(k) + T(n-k)Why is the time complexity of this algorithm exponential?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-3















If I have the following algorithm



for (i = 1; i <= 4 * n; i = i * 4) 
for (k = 1; k < 1000; k = 2 * k)
print(k);

print(i);



how can I calculate its complexity?
I only understand that for one iteration of for(i=1; i≤4n; i=i*4), the line with print(i) is O(1), and for one iteration of for(k=1; k<1000; k=2*k), the line with print(k) is O(1).



I'm not sure how to proceed.










share|improve this question
























  • Possible duplicate of Big O, how do you calculate/approximate it?

    – Prune
    Mar 22 at 21:44











  • If you search on the phrase "determine computational complexity" or any reference on SO, you’ll find resources that can explain it much better than we can in an answer here.

    – Prune
    Mar 22 at 21:56

















-3















If I have the following algorithm



for (i = 1; i <= 4 * n; i = i * 4) 
for (k = 1; k < 1000; k = 2 * k)
print(k);

print(i);



how can I calculate its complexity?
I only understand that for one iteration of for(i=1; i≤4n; i=i*4), the line with print(i) is O(1), and for one iteration of for(k=1; k<1000; k=2*k), the line with print(k) is O(1).



I'm not sure how to proceed.










share|improve this question
























  • Possible duplicate of Big O, how do you calculate/approximate it?

    – Prune
    Mar 22 at 21:44











  • If you search on the phrase "determine computational complexity" or any reference on SO, you’ll find resources that can explain it much better than we can in an answer here.

    – Prune
    Mar 22 at 21:56













-3












-3








-3








If I have the following algorithm



for (i = 1; i <= 4 * n; i = i * 4) 
for (k = 1; k < 1000; k = 2 * k)
print(k);

print(i);



how can I calculate its complexity?
I only understand that for one iteration of for(i=1; i≤4n; i=i*4), the line with print(i) is O(1), and for one iteration of for(k=1; k<1000; k=2*k), the line with print(k) is O(1).



I'm not sure how to proceed.










share|improve this question
















If I have the following algorithm



for (i = 1; i <= 4 * n; i = i * 4) 
for (k = 1; k < 1000; k = 2 * k)
print(k);

print(i);



how can I calculate its complexity?
I only understand that for one iteration of for(i=1; i≤4n; i=i*4), the line with print(i) is O(1), and for one iteration of for(k=1; k<1000; k=2*k), the line with print(k) is O(1).



I'm not sure how to proceed.







c time-complexity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 22:31









chqrlie

64.3k852108




64.3k852108










asked Mar 22 at 17:40









Rosario Di PalmaRosario Di Palma

31




31












  • Possible duplicate of Big O, how do you calculate/approximate it?

    – Prune
    Mar 22 at 21:44











  • If you search on the phrase "determine computational complexity" or any reference on SO, you’ll find resources that can explain it much better than we can in an answer here.

    – Prune
    Mar 22 at 21:56

















  • Possible duplicate of Big O, how do you calculate/approximate it?

    – Prune
    Mar 22 at 21:44











  • If you search on the phrase "determine computational complexity" or any reference on SO, you’ll find resources that can explain it much better than we can in an answer here.

    – Prune
    Mar 22 at 21:56
















Possible duplicate of Big O, how do you calculate/approximate it?

– Prune
Mar 22 at 21:44





Possible duplicate of Big O, how do you calculate/approximate it?

– Prune
Mar 22 at 21:44













If you search on the phrase "determine computational complexity" or any reference on SO, you’ll find resources that can explain it much better than we can in an answer here.

– Prune
Mar 22 at 21:56





If you search on the phrase "determine computational complexity" or any reference on SO, you’ll find resources that can explain it much better than we can in an answer here.

– Prune
Mar 22 at 21:56












1 Answer
1






active

oldest

votes


















3














Here's the inner loop:



for(k=1; k<1000; k=2*k) 
print(k);



That loop is constant time, because there are no free variables. It's always going to call print exactly 9 times, for k ∈ 1,2,4,8,16,32,64,128,256,512.



The outer loop is O(log n), because it will execute ⌊log₄ 4n⌋ times.



Overall, the program fragment you posted (if we add the final closing brace you omitted) is O(log n).






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%2f55305114%2falgorithm-complexity-with-iterations-is-it-logarithmic-or-exponential%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Here's the inner loop:



    for(k=1; k<1000; k=2*k) 
    print(k);



    That loop is constant time, because there are no free variables. It's always going to call print exactly 9 times, for k ∈ 1,2,4,8,16,32,64,128,256,512.



    The outer loop is O(log n), because it will execute ⌊log₄ 4n⌋ times.



    Overall, the program fragment you posted (if we add the final closing brace you omitted) is O(log n).






    share|improve this answer



























      3














      Here's the inner loop:



      for(k=1; k<1000; k=2*k) 
      print(k);



      That loop is constant time, because there are no free variables. It's always going to call print exactly 9 times, for k ∈ 1,2,4,8,16,32,64,128,256,512.



      The outer loop is O(log n), because it will execute ⌊log₄ 4n⌋ times.



      Overall, the program fragment you posted (if we add the final closing brace you omitted) is O(log n).






      share|improve this answer

























        3












        3








        3







        Here's the inner loop:



        for(k=1; k<1000; k=2*k) 
        print(k);



        That loop is constant time, because there are no free variables. It's always going to call print exactly 9 times, for k ∈ 1,2,4,8,16,32,64,128,256,512.



        The outer loop is O(log n), because it will execute ⌊log₄ 4n⌋ times.



        Overall, the program fragment you posted (if we add the final closing brace you omitted) is O(log n).






        share|improve this answer













        Here's the inner loop:



        for(k=1; k<1000; k=2*k) 
        print(k);



        That loop is constant time, because there are no free variables. It's always going to call print exactly 9 times, for k ∈ 1,2,4,8,16,32,64,128,256,512.



        The outer loop is O(log n), because it will execute ⌊log₄ 4n⌋ times.



        Overall, the program fragment you posted (if we add the final closing brace you omitted) is O(log n).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 22 at 17:48









        rob mayoffrob mayoff

        298k43601648




        298k43601648





























            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%2f55305114%2falgorithm-complexity-with-iterations-is-it-logarithmic-or-exponential%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript