Understanding Big O Notation for Algorithm Efficiency

𝗟𝗲𝘁'𝘀 𝘁𝗮𝗹𝗸 𝗮𝗯𝗼𝘂𝘁 𝗔𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺𝘀! Let's start our series with the most familiar topic - 𝗕𝗶𝗴 𝗢. The concept of Big O describes how the 𝗿𝘂𝗻𝗻𝗶𝗻𝗴 𝘁𝗶𝗺𝗲 𝗼𝗿 𝗺𝗲𝗺𝗼𝗿𝘆 𝗰𝗼𝗻𝘀𝘂𝗺𝗽𝘁𝗶𝗼𝗻 of an algorithm increases as its input grows. That is, it is a way of measuring the efficiency of code in terms of the size of the input, regardless of the computer or the language in which it is written. We've all heard of the terms O(n), O(1) or O(n²) and didn't exactly understand what they meant. 💠𝘖(1) - 𝘊𝘰𝘯𝘴𝘵𝘢𝘯𝘵 𝘛𝘪𝘮𝘦 The running time does not change even if the input size increases. For example: Direct access to an element in an array by index (arr[0]). It doesn't matter if the array has 10 elements or a million - the operation will take the same time. 💠𝘖(𝘯) - 𝘓𝘪𝘯𝘦𝘢𝘳 𝘛𝘪𝘮𝘦 The running time increases at the same rate as the input. For example: Looping through all elements of an array. If we increase the amount of data by 2 times - the running time will also increase by about 2 times. 💠𝘖(𝘯2) - 𝘘𝘶𝘢𝘥𝘳𝘢𝘵𝘪𝘤 𝘛𝘪𝘮𝘦 The running time increases by the square of the input size. For example: A loop within a loop that goes through each element in front of every other element. If we increase the input by 2 times - the running time will increase by 4 times. #algorithms #BigO #javaScript #Developres #fullStack

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories