The app for independent voices

๐—•๐—ถ๐—ด-๐—ข ๐—ก๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ต๐—ฒ๐—ฎ๐˜ ๐—ฆ๐—ต๐—ฒ๐—ฒ๐˜

Big O notation is a mathematical shorthand used to describe the runtime of algorithms.

It's a fundamental concept in computer science that helps us understand how an algorithm's performance changes as the input size grows.

๐—•๐—ถ๐—ด-๐—ข ๐—ก๐—ผ๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป expresses the upper bound of an algorithm's runtime (in terms of space or time complexity). It tells us how the algorithm's runtime grows as the input size increases in the worst case.

Time complexity measures how long an algorithm takes to run, while space complexity measures how much memory an algorithm requires.

To analyze the Big O notation of an algorithm, we need to identify the dominant term in the runtime function.

The dominant term is the term that grows the fastest as the input size increases. All other terms can be ignored.

Examples of time complexity using Big-O notation:

๐Ÿ”ต ๐—ข(๐Ÿญ): ๐—–๐—ผ๐—ป๐˜€๐˜๐—ฎ๐—ป๐˜ ๐˜๐—ถ๐—บ๐—ฒ. The runtime of the algorithm does not depend on the input size. An example is accessing a specific element of an array.

๐Ÿ”ต ๐—ข(๐—น๐—ผ๐—ด ๐—ป): ๐—Ÿ๐—ผ๐—ด๐—ฎ๐—ฟ๐—ถ๐˜๐—ต๐—บ๐—ถ๐—ฐ ๐˜๐—ถ๐—บ๐—ฒ. The runtime of the algorithm grows logarithmically with the input size. An example is using binary search to find an element in a sorted array.

๐ŸŸก ๐—ข(๐—ป): ๐—Ÿ๐—ถ๐—ป๐—ฒ๐—ฎ๐—ฟ ๐˜๐—ถ๐—บ๐—ฒ. The runtime of the algorithm grows linearly with the input size. An example is finding an element in an unsorted array.

๐ŸŸก ๐—ข(๐—ป ๐—น๐—ผ๐—ด ๐—ป): ๐—Ÿ๐—ผ๐—ด-๐—น๐—ถ๐—ป๐—ฒ๐—ฎ๐—ฟ ๐˜๐—ถ๐—บ๐—ฒ. The runtime of the algorithm grows log-linearly with the input size. Examples include efficient sorting algorithms such as Quicksort and Heapsort.

๐ŸŸ  ๐—ข(๐—ป^๐Ÿฎ): ๐—ค๐˜‚๐—ฎ๐—ฑ๐—ฟ๐—ฎ๐˜๐—ถ๐—ฐ ๐˜๐—ถ๐—บ๐—ฒ. The algorithm's runtime grows quadratically with the input size. Simple sorting algorithms, such as insertion or selection sort, are examples.

๐Ÿ”ด ๐—ข(๐Ÿฎ^๐—ป): ๐—˜๐˜…๐—ฝ๐—ผ๐—ป๐—ฒ๐—ป๐˜๐—ถ๐—ฎ๐—น ๐˜๐—ถ๐—บ๐—ฒ. The runtime of the algorithm grows exponentially with the input size. An example is the recursive Fibonacci method.

โ™ป๏ธ Reshare if you found this helpful.

Dec 31
at
9:14 AM
Relevant people

Log in or sign up

Join the most interesting and insightful discussions.