{"id":21814,"date":"2020-08-28T10:35:03","date_gmt":"2020-08-28T17:35:03","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=21814"},"modified":"2020-08-28T11:11:51","modified_gmt":"2020-08-28T18:11:51","slug":"big-o-notation-time","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/","title":{"rendered":"Big O Notation &#8211; Time Complexity"},"content":{"rendered":"\n<p>As software engineers, sometimes our job is to come up with a solution to a problem that requires some sort of algorithm. An algorithm, at a high level, is just a set of directions \u2013 the recipe to solve a problem. When do we get to a point where we know the \u201crecipe\u201d we have written to solve our problem is \u201cgood\u201d enough?<br><\/p>\n\n\n\n<p>This is where Big O Notation comes in. The Big O Notation is used to describe two things: the space complexity and the time complexity of an algorithm. In this article, we cover time complexity: what it is, how to figure it out, and why knowing the time complexity \u2013 the Big O Notation \u2013 of an algorithm can improve your approach.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Time Complexity<\/h2>\n\n\n\n<p>The Big O Notation for time complexity gives a rough idea of how long it will take an algorithm to execute based on two things: the size of the input it has and the amount of steps it takes to complete. We compare the two to get our runtime. Time complexity measures how efficient an algorithm is when it has an extremely large dataset. We look at the absolute worst-case scenario and call this our Big O Notation.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">O(1)<\/h3>\n\n\n\n<p>The first Big O measurement we talk about is constant time, or <code>O(1)<\/code> (oh of one). When we talk about things in constant time, we are talking about declarations or operations of some sort: <br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\/\/variable declarations\nlet number = 9;\n\/\/evaluating arithmetic expressions\nlet x = 5 + 7;\nif(x &lt; 5) {\n\/\/other code here that is evaluated separately\n}<\/pre><\/div>\n\n\n\n<p>Pretty much anything evaluated only one time in our algorithm is counted as constant time.<br><\/p>\n\n\n\n<p>When evaluating overall running time, we typically ignore these statements since they don\u2019t factor into the complexity. Be aware that <code>O(1)<\/code> expressions exist and why an expression might be <code>O(1)<\/code> as opposed to any other possible value.&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">O(n)<\/h3>\n\n\n\n<p>Take a look at this example:&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const exampleOne = (arr) =&gt; {\n   for(let i = 0; i &lt; arr.length; i++) {\n     console.log(arr[i].first_name + &quot; &quot; + arr[i].last_name);\n   }\n }\n \n let arr1 = [{\n   &quot;id&quot;: 1,\n   &quot;first_name&quot;: &quot;Mina&quot;,\n   &quot;last_name&quot;: &quot;Strain&quot;,\n   &quot;email&quot;: &quot;mstrain0@sfgate.com&quot;\n }, {\n   &quot;id&quot;: 2,\n   &quot;first_name&quot;: &quot;Reinhold&quot;,\n   &quot;last_name&quot;: &quot;Adicot&quot;,\n   &quot;email&quot;: &quot;radicot1@sun.com&quot;\n }, {\n   &quot;id&quot;: 3,\n   &quot;first_name&quot;: &quot;Tades&quot;,\n   &quot;last_name&quot;: &quot;Mundy&quot;,\n   &quot;email&quot;: &quot;tmundy2@patch.com&quot;\n }, {\n   &quot;id&quot;: 4,\n   &quot;first_name&quot;: &quot;Sawyere&quot;,\n   &quot;last_name&quot;: &quot;Ingre&quot;,\n   &quot;email&quot;: &quot;singre3@pinterest.com&quot;\n }, {\n   &quot;id&quot;: 5,\n   &quot;first_name&quot;: &quot;Amber&quot;,\n   &quot;last_name&quot;: &quot;Reddington&quot;,\n   &quot;email&quot;: &quot;areddington4@1und1.de&quot;\n }];\n \n let arr2 = [{\n   \/*\n       Go to mockaroo.com and create fake JSON data that has 100 rows. Preview the array and copy\/paste it here.\n   *\/\n}];\n \n \n \n exampleOne(arr1);\n \/\/exampleOne(arr2); \/\/uncomment this when ready to test<\/pre><\/div>\n\n\n\n<p>Take a look at the first dataset of the example. What is the length of the array? Take a look again, but this time at the second data set you created by going to mockaroo.com \u2013 what is the length of that array?&nbsp;<br><\/p>\n\n\n\n<p>Now let\u2019s look at the actual function since the length of our input is known. To figure out the Big O of an algorithm, take a look at things block-by-block and eliminate the non-essential blocks of code. Once you have cancelled out what you don\u2019t need to figure out the runtime, you can figure out the math to get the correct answer.&nbsp;<br><\/p>\n\n\n\n<p>In this example, we have a for loop. That for loop iterates over every item in the array we pass to it. Because the code has to touch<em> every <\/em>single element in the array to complete its execution, it\u2019s linear time, or <code>O(n)<\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Final Thoughts on O(n):<\/h4>\n\n\n\n<p>Because we describe Big O in terms of worst-case scenario, it doesn\u2019t matter if we have a for loop that\u2019s looped 10 times or 100 times before the loop breaks. The rate of growth in the amount of time as the inputs increase is still linear.&nbsp;<br><\/p>\n\n\n\n<p>One final example:&nbsp;<br><\/p>\n\n\n\n<p>Take the same function as above, but add another block of code to it:&nbsp;<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const exampleTwo = (arr) =&gt; {\n   for(let i = 0; i &lt; arr.length; i++) {\n     console.log(arr[i].first_name + &quot; &quot; + arr[i].last_name);\n   };\n   for(let i = 0; i &lt; arr.length; i++) {\n     console.log(arr[i].first_name + &quot; &quot; + &quot; - CareerKarma Student&quot;);\n   }\n \n }<\/pre><\/div>\n\n\n\n<p>What would be the runtime of this function?&nbsp;<br><\/p>\n\n\n\n<p>Technically, it\u2019s <code>O(2n)<\/code>, because we are looping through two for loops, one after the other<em>.<\/em><br><\/p>\n\n\n\n<p>However, when expressing time complexity in terms of Big O Notation, we look at only the most essential parts. This means the coefficient in 2n \u2013 the 2 \u2013 is meaningless. It doesn\u2019t matter how many loops we have stacked on top of each other \u2013 the Big O will still be <code>O(n)<\/code> because we are looping through the same array.&nbsp;<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">One thing to note:&nbsp;<\/h5>\n\n\n\n<p>If you are creating an algorithm that is working with two arrays and you have for loops stacked on top of each other that use one or the other array, technically the runtime is not <code>O(n)<\/code>, unless the lengths of the two separate arrays are the same.<br><\/p>\n\n\n\n<p>When handling different datasets in a function \u2013 in this case two arrays of differing lengths \u2013 we count that separately. We use another variable to stand for the other array that has a different length.<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const exampleThree = (arr1, arr2) =&gt; {\n   for(let i = 0; i &lt; arr1.length; i++) {\n     console.log(arr[i].first_name + &quot; &quot; + &quot; - CareerKarma Career Coach&quot;);\n   };\n   for(let i = 0; i &lt; arr2.length; i++) {\n     console.log(arr[i].first_name + &quot; &quot; + &quot; - CareerKarma Student&quot;);\n   }\n \n }<\/pre><\/div>\n\n\n\n<p>The time complexity of this problem is <code>O(n + m)<\/code>. The n here is one array and its elements; the m is the other array and its elements. Because we are dealing with two different lengths, and we don\u2019t know which one has more elements, it cannot quite be reduced down to <code>O(n)<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basics of Logarithms and Exponents<\/h3>\n\n\n\n<p>Before we talk about other possible time complexity values, have a very basic understanding of how exponents and logarithms work.&nbsp;<br><\/p>\n\n\n\n<p>Many see the words \u201cexponent\u201d, \u201clog\u201d or \u201clogarithm\u201d and get nervous that they will have to do algebra or math they won\u2019t remember from school. This is not the case! In this section, we look at a very high level about what a log is, what an exponent is, and how each compares to the runtime of an <code>O(n)<\/code> function.<br><\/p>\n\n\n\n<p>To look at logarithms and how they work, remind ourselves of how exponents work. The syntax for raising something to an exponent is:&nbsp;<\/p>\n\n\n\n<p><strong>x<\/strong><strong><sup>y <\/sup><\/strong><strong>= z<\/strong><\/p>\n\n\n\n<p>We commonly read this as \u201cx to the y power equals z\u201d. The variable z is x multiplied by itself y times.<br><\/p>\n\n\n\n<p>Logarithmic syntax is:<br><\/p>\n\n\n\n<p><strong>log<\/strong><strong><sub>x<\/sub><\/strong><strong> z = y<\/strong><\/p>\n\n\n\n<p>Read this as \u201clog base x of z equals y\u201d. Look how the variables compare to the previous equation. If we take the base, raise it to the result, we get the number we\u2019re trying to take the log of. It\u2019s basically the inverse of what an exponent is.<br><\/p>\n\n\n\n<p>An important takeaway here is when we deal with exponents, we deal with a result that is a large number. When we deal with logarithms, we deal with a smaller number as the result.<br><\/p>\n\n\n\n<p>So&#8230;how does this connect with Big O Notation? You\u2019ll see in the next few sections!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">O(n<sup>x<\/sup>)<\/h3>\n\n\n\n<p>So far, we have talked about constant time and linear time. O(n<sup>2<\/sup>), a version of O(n<sup>x<\/sup>) where x is equal to 2, is called quadratic time. This means as the size of the input increases, the number of steps to solve the problem in the worst-case is squared or raised to the x power.&nbsp;<br><\/p>\n\n\n\n<p>This can happen when we need to nest loops together to compare an i-th value to another value in an array. See if there are duplicates in an array:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const exampleArr = [1, 5, 13, 45, 2, 5, 31, 9, 45];\nconst exampleFour = (arr) =&gt; {\n   for(let i = 0; i &lt; arr.length; i++) {\n     for(let j = 0; j &lt; arr.length; j++) {\n     \t   if(arr[i] === arr[j] &amp;&amp; j !== 0) {\n          return true;\n        }\n     }\n   };\n\t\n   return false;\n }<\/pre><\/div>\n\n\n\n<p>The first loop marks our i-th placement in the array. The second loop looks at every other index in the array to see if it matches the i-th index. If none match and it gets to the end of the loop, the i-th pointer moves to the next index.<br><\/p>\n\n\n\n<p>This means we look at each index twice in our algorithm. This makes, in this example, an array with a length of 9 take at worst-case take 81 (9<sup>2<\/sup>) steps. For small datasets, this runtime is acceptable. But when we increase the dataset drastically (say to 1,000,000,000 entries), O(n<sup>x<\/sup>) runtime doesn\u2019t look so great.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Final thoughts on O(n<sup>x<\/sup>)<\/h4>\n\n\n\n<p>Always try to create algorithms with a more optimal runtime than O(n<sup>x<\/sup>). You are likely to be dealing with a set of data much larger than the array we have here. Next, let\u2019s take a look at the inverse of a polynomial runtime: logarithmic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">O(log n)<\/h3>\n\n\n\n<p>Imagine a phone book. If we are to give you a person\u2019s name and you are to look it up, how will you go about doing that?&nbsp;<br><\/p>\n\n\n\n<p>An algorithm that starts at the beginning of the book and runs through every name until it gets to the name it\u2019s looking for, runs in <code>O(n)<\/code> runtime \u2013 the worst case scenario is that the person you are looking for is the very last name.&nbsp;<br><\/p>\n\n\n\n<p>What can we do to improve on that? How can we make it better than linear runtime?<br><\/p>\n\n\n\n<p>We can do an algorithm called binary search. We won\u2019t go over the ins and outs of how to code out binary search, but if you understand how it works through some pseudocode, you can see why it\u2019s a little bit better than <code>O(n)<\/code>.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Pseudocode for Binary Search<\/h4>\n\n\n\n<p>Consider this: a phone book as an array of objects where each object has a firstName, lastName and phoneNumber. Here\u2019s a snippet:&nbsp;<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const phoneBook = [{\n   &quot;firstName&quot;: &quot;Mina&quot;,\n   &quot;lastName&quot;: &quot;Adicot&quot;,\n   &quot;phoneNumber&quot;: &quot;123-456-7890&quot;\n }, {\n   &quot;firstName&quot;: &quot;Reinhold&quot;,\n   &quot;lastName&quot;: &quot;Atherton&quot;,\n   &quot;phoneNumber&quot;: &quot;908-765-4321&quot;\n },<\/pre><\/div>\n\n\n\n<ol class=\"wp-block-list\"><li>Since the phone book is already sorted by last name, we can&nbsp; see if the midpoint\u2019s lastName property matches the search term\u2019s last name.&nbsp;<\/li><li>If not, and the first letter comes after the current midpoint\u2019s last name\u2019s first letter, we do away with the first half.&nbsp;<\/li><li>If it comes before, take away the second half.<\/li><li>If it\u2019s equal, look at the next letter and compare the substrings to each other using steps 1-3.&nbsp;<\/li><li>Keep doing this action until we find the answer. If we don\u2019t find the answer, say so.&nbsp;<\/li><\/ol>\n\n\n\n<p>This is called binary search. It has a <code>O(log n)<\/code> runtime because we do away with a section of our input every time until we find the answer.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Final Thoughts on O(log n)<\/h4>\n\n\n\n<p>Recall our basic logarithm equation. The result when we take a log of a number is always smaller. If <code>O(n)<\/code> is linear and O(n<sup>2<\/sup>) takes more steps, then <code>O(log n)<\/code> is slightly better than <code>O(n)<\/code> because when we take the log of n it\u2019s a smaller number.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">O(2<sup>n<\/sup>)<\/h3>\n\n\n\n<p>O(2<sup>n<\/sup>) typically refers to recursive solutions that involve some sort of operation. The Fibonacci sequence is the most popular example of this runtime. This particular example will return the nth number in the Fibonacci sequence:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const exampleFive = (n) =&gt; {\n   if(n === 0)\n     return 0;\n   }\n   else if(n === 1)\n     return 1;\n   }\n   else{\n     return exampleFive(n - 1) + exampleFive(n - 2);\n   }\n }<\/pre><\/div>\n\n\n\n<p>This solution increases the amount of steps needed to complete the problem at an exponential rate. Avoid this particular runtime at all costs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">O(n log n)<\/h3>\n\n\n\n<p>The <code>O(n log n)<\/code> runtime is very similar to the <code>O(log n)<\/code> runtime, except that it performs worse than a linear runtime. Essentially, what an <code>O(n log n)<\/code> runtime algorithm has is some kind of linear function that has a nested logarithmic function. Take this example:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const n = 2000;\nconst exampleSix = (n) =&gt; {\n  let sum = 0\n    for (let i = 0; i &lt; n; i++){\n      let j = 1\n      while j &lt; n {        \n        j *= 2\n        sum += 1\n      }\n    }\n}<\/pre><\/div>\n\n\n\n<p>In this code snippet, we are incrementing a counter starting at 0 and then using a while loop inside that counter to multiply j by two on every pass through \u2013 this makes it logarithmic since we are essentially doing large leaps on every iteration by using multiplication.&nbsp;<br><\/p>\n\n\n\n<p>Since it\u2019s nested we multiply the Big O notation values together instead of add. We add when we have separate blocks of code. O(n) x O(log n) === O(n log n).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">O(n!)<\/h3>\n\n\n\n<p>To have a runtime of <code>O(n!)<\/code>, the algorithm has to be extremely slow, even on smaller inputs. One of the more famous simple examples of an algorithm with a slow runtime is one finds every permutation in a string.<br><\/p>\n\n\n\n<p>In this algorithm, as the length of your input increases, the number of returned permutations is the length of input ! (factorial).<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>permutation('a') \/\/ 1 &quot;a&quot;\npermutation('ab') \/\/ 2 &quot;ab&quot;, &quot;ba&quot;\npermutation('abc') \/\/ 6 &quot;abc&quot;, &quot;bca&quot;, &quot;cab&quot;, &quot;cba&quot;, &quot;acb&quot;, &quot;bac&quot;\npermutation('abcd') \/\/ 24 permutation('abcde') \/\/ 120  \n\nnum of permutations is the length of the input factorial.<\/pre><\/div>\n\n\n\n<p>Factorial, if you recall is the nth number multiplied by every number that comes before it until you get to 1.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const factorial = (n) =&gt; {\n   if(n &lt; 2) {\n       return 1;\n   } else {\n       return n * factorial(n - 1);\n   }\n};<\/pre><\/div>\n\n\n\n<p>If we look at a length of 3, for example, we multiple 3 x 2 x 1 === 6. Six is 3!.<br><\/p>\n\n\n\n<p>It doesn\u2019t take a very long or very large input for an algorithm to take a really long time to complete when the runtime is this slow. At all costs, try to find something more efficient if you can. This is okay for a naive or first-pass solution to a problem, but definitely needs to be refactored to be better somehow.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Rules to Remember<\/h2>\n\n\n\n<p>There are some basic things to remember when trying to figure out the time complexity of a function:&nbsp;<br><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Constants are good to be aware of but don\u2019t necessarily need to be counted. This includes declarations, arithmetic operations, and coefficients or multiples of the same runtime (i.e. if we have two loop stacked on top of each other with same runtime, we don\u2019t count it as O(2n) \u2013 it\u2019s just O(n).&nbsp;<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\"><li>Big O Notation only concerns itself with the upper bound, or worst-case scenario when it comes to time complexity.&nbsp;<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\"><li>When you have multiple blocks of code with different runtimes stacked on top of each other, keep only the worst-case value and count that as your runtime. It\u2019s the most significant block of code in your function that will have an effect on the overall complexity.&nbsp;<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>To recap, the Big O Notation can have two meanings associated with it: time complexity and space complexity. In this article we\u2019ve looked closely at time complexity. This is figured as how much time it takes for the algorithm to complete when its input increases. This is important when we interact with very large datasets \u2013 which you are likely to do with an employer. Here is a graph that can serve as a cheat sheet until you get to know the Big O Notation better: <\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"960\" height=\"720\" src=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/Big-O-Notation.png\" alt=\"Graph that illustrates how the runtime increases when the input of your algorithm increases.\" class=\"wp-image-21827\" srcset=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/Big-O-Notation.png 960w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/Big-O-Notation-768x576.png 768w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/Big-O-Notation-770x578.png 770w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/Big-O-Notation-20x15.png 20w, https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/Big-O-Notation-385x289.png 385w\" sizes=\"auto, (max-width: 960px) 100vw, 960px\" \/><figcaption>As the size of the input increases, you can take a visual look to see how the number of operations increases. This will give you a sense of what an efficient runtime is for more basic algorithms.  <\/figcaption><\/figure>\n\n\n\n<p>Being aware of the Big O Notation, how it\u2019s calculated, and what would be considered an acceptable time complexity for an algorithm will give you an edge over other candidates when you look for a job.<\/p>\n","protected":false},"excerpt":{"rendered":"As software engineers, sometimes our job is to come up with a solution to a problem that requires some sort of algorithm. An algorithm, at a high level, is just a set of directions \u2013 the recipe to solve a problem. When do we get to a point where we know the \u201crecipe\u201d we have&hellip;","protected":false},"author":77,"featured_media":21815,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[18070],"tags":[],"class_list":{"0":"post-21814","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-software-engineering-skills"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Software Engineering","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":[]},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Big O Notation - Time Complexity %<\/title>\n<meta name=\"description\" content=\"Take a deep dive into time complexity with this article on Big O Notation to learn what Big O is and how to figure it out.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Big O Notation - Time Complexity\" \/>\n<meta property=\"og:description\" content=\"Take a deep dive into time complexity with this article on Big O Notation to learn what Big O is and how to figure it out.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-28T17:35:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-28T18:11:51+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/spacex-PIOgkhaF3WA-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Christina Kopecky\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christina Kopecky\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/\"},\"author\":{\"name\":\"Christina Kopecky\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"headline\":\"Big O Notation &#8211; Time Complexity\",\"datePublished\":\"2020-08-28T17:35:03+00:00\",\"dateModified\":\"2020-08-28T18:11:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/\"},\"wordCount\":2227,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/spacex-PIOgkhaF3WA-unsplash.jpg\",\"articleSection\":[\"Software Engineering\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/\",\"name\":\"Big O Notation - Time Complexity %\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/spacex-PIOgkhaF3WA-unsplash.jpg\",\"datePublished\":\"2020-08-28T17:35:03+00:00\",\"dateModified\":\"2020-08-28T18:11:51+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\"},\"description\":\"Take a deep dive into time complexity with this article on Big O Notation to learn what Big O is and how to figure it out.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/spacex-PIOgkhaF3WA-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/spacex-PIOgkhaF3WA-unsplash.jpg\",\"width\":1020,\"height\":680,\"caption\":\"Time lapse photo of light at Kennedy Space Center\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/big-o-notation-time\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Software Engineering\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/software-engineering-skills\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Big O Notation &#8211; Time Complexity\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/ae0cdc4a5d198690d78482646894074e\",\"name\":\"Christina Kopecky\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/image-3-150x150.jpg\",\"caption\":\"Christina Kopecky\"},\"description\":\"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.\",\"sameAs\":[\"http:\\\/\\\/www.linkedin.com\\\/in\\\/cmvnk\"],\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/christina-kopecky\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Big O Notation - Time Complexity %","description":"Take a deep dive into time complexity with this article on Big O Notation to learn what Big O is and how to figure it out.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/","og_locale":"en_US","og_type":"article","og_title":"Big O Notation - Time Complexity","og_description":"Take a deep dive into time complexity with this article on Big O Notation to learn what Big O is and how to figure it out.","og_url":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-28T17:35:03+00:00","article_modified_time":"2020-08-28T18:11:51+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/spacex-PIOgkhaF3WA-unsplash.jpg","type":"image\/jpeg"}],"author":"Christina Kopecky","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"Christina Kopecky","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/"},"author":{"name":"Christina Kopecky","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"headline":"Big O Notation &#8211; Time Complexity","datePublished":"2020-08-28T17:35:03+00:00","dateModified":"2020-08-28T18:11:51+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/"},"wordCount":2227,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/spacex-PIOgkhaF3WA-unsplash.jpg","articleSection":["Software Engineering"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/","url":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/","name":"Big O Notation - Time Complexity %","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/spacex-PIOgkhaF3WA-unsplash.jpg","datePublished":"2020-08-28T17:35:03+00:00","dateModified":"2020-08-28T18:11:51+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e"},"description":"Take a deep dive into time complexity with this article on Big O Notation to learn what Big O is and how to figure it out.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/big-o-notation-time\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/spacex-PIOgkhaF3WA-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/spacex-PIOgkhaF3WA-unsplash.jpg","width":1020,"height":680,"caption":"Time lapse photo of light at Kennedy Space Center"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/big-o-notation-time\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Software Engineering","item":"https:\/\/careerkarma.com\/blog\/software-engineering-skills\/"},{"@type":"ListItem","position":3,"name":"Big O Notation &#8211; Time Complexity"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/ae0cdc4a5d198690d78482646894074e","name":"Christina Kopecky","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/image-3-150x150.jpg","caption":"Christina Kopecky"},"description":"Christina is an experienced technical writer, covering topics as diverse as Java, SQL, Python, and web development. She earned her Master of Music in flute performance from the University of Kansas and a bachelor's degree in music with minors in French and mass communication from Southeast Missouri State. Prior to joining the Career Karma team in June 2020, Christina was a teaching assistant, team lead, and section lead at Lambda School, where she led student groups, performed code and project reviews, and debugged problems for students. Christina's technical content is featured frequently in publications like Codecademy, Repl.it, and Educative.","sameAs":["http:\/\/www.linkedin.com\/in\/cmvnk"],"url":"https:\/\/careerkarma.com\/blog\/author\/christina-kopecky\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/21814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/77"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=21814"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/21814\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/21815"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=21814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=21814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=21814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}