{"id":25039,"date":"2017-05-27T17:22:06","date_gmt":"2017-05-27T11:52:06","guid":{"rendered":"https:\/\/www.wikitechy.com\/technology\/?p=25039"},"modified":"2017-05-27T17:22:06","modified_gmt":"2017-05-27T11:52:06","slug":"time-complexity-where-loop-variable-is-incremented-by-1-2-3-4","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/technology\/time-complexity-where-loop-variable-is-incremented-by-1-2-3-4\/","title":{"rendered":"Time Complexity where loop variable is incremented by 1,2,3,4"},"content":{"rendered":"<p>What is the Time Complexity where loop variable is incremented by 1,2,3,4 of below code?<\/p>\n[ad type=&#8221;banner&#8221;]\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-c code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-c code-embed-code\">void fun(int n)<br\/>{<br\/>   int j = 1, i = 0;<br\/>   while (i &lt; n)<br\/>   {<br\/>       \/\/ Some O(1) task<br\/>       i = i + j;<br\/>       j++;<br\/>   }<br\/>}<\/code><\/pre> <\/div>\n<p>The<a href=\"https:\/\/www.wikitechy.com\/technology\/space-complexity-mean\/\"> loop variable<\/a> \u2018i\u2019 is incremented by 1, 2, 3, 4, \u2026 until i becomes greater than or equal to n.<\/p>\n<p>The value of i is x(x+1)\/2 after x iterations. So if loop runs x times, then x(x+1)\/2 &lt; n. Therefore time complexity can be written as \u0398(\u221an).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time Complexity where loop variable is incremented by 1, 2, 3, 4 &#8211;  Analysis of Algorithm &#8211; What is the time complexity of below code?The loop variable \u2018i\u2019<\/p>\n","protected":false},"author":1,"featured_media":25326,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70146],"tags":[70247,70250,70243,69992,70959,70249,70246,70958,70251,70558,70561,70551,70236,71491,71607,71493,71606,70532],"class_list":["post-25039","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analysis-of-algorithm","tag-algorithm-analysis-and-design","tag-algorithm-complexity","tag-algorithm-design-and-analysis","tag-analysis-of-algorithms","tag-daa-algorithm","tag-data-analysis-and-algorithm","tag-design-analysis-and-algorithm","tag-design-and-analysis-of-algorithms-algorithm","tag-design-and-analysis-of-algorithms-book","tag-how-to-calculate-time-complexity-for-a-given-algorithm","tag-how-to-calculate-time-complexity-of-a-program-in-c","tag-how-to-find-time-complexity-of-an-algorithm","tag-introduction-to-algorithms","tag-questions-on-time-complexity-of-algorithms","tag-space-complexity-of-an-algorithm","tag-time-complexity-of-algorithms-examples","tag-time-complexity-of-for-loop","tag-time-complexity-of-sorting-algorithms"],"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/25039","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/comments?post=25039"}],"version-history":[{"count":0,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/posts\/25039\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media\/25326"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/media?parent=25039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/categories?post=25039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/technology\/wp-json\/wp\/v2\/tags?post=25039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}