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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현