๐Ÿš€ Why Do We Care About Execution Time and Memory Usage?

๐Ÿš€ ู„ู…ุงุฐุง ู†ู‡ุชู… ุจุฒู…ู† ุงู„ุชู†ููŠุฐ ูˆุงุณุชู‡ู„ุงูƒ ุงู„ุฐุงูƒุฑุฉุŸ

This topic will accompany us throughout our programming career. When writing a program, itโ€™s important to know if itโ€™s fast and efficient. Therefore, we analyze:

Nowadays, we tend to focus more on execution time than memory usage, because modern hardware provides much more memory and processing power than before.

ู‡ุฐุง ุงู„ู…ูˆุถูˆุน ุณูˆู ูŠุฑุงูู‚ู†ุง ุทูˆุงู„ ุญูŠุงุชู†ุง ุงู„ุจุฑู…ุฌูŠุฉุ› ุนู†ุฏู…ุง ู†ูƒุชุจ ุจุฑู†ุงู…ุฌุŒ ู…ู† ุงู„ู…ู‡ู… ุฃู† ู†ุนุฑู ุฅู† ูƒุงู† ุณุฑูŠุนู‹ุง ูˆุฐูˆ ุฃุฏุงุก ุนุงู„ู. ู„ุฐู„ูƒ ู†ู‚ูˆู… ุจุชุญู„ูŠู„:

ููŠ ุงู„ูˆู‚ุช ุงู„ุญุงู„ูŠ ุฃุตุจุญ ุชุฑูƒูŠุฒู†ุง ุบุงู„ุจู‹ุง ุนู„ู‰ ุงู„ุฒู…ู† ุฃูƒุซุฑ ู…ู† ุงู„ู…ุณุงุญุฉุŒ ุจุณุจุจ ุงู„ุชุทูˆุฑ ุงู„ูƒุจูŠุฑ ููŠ ู‚ุฏุฑุงุช ุงู„ุฃุฌู‡ุฒุฉ ู…ู† ุญูŠุซ ุงู„ุฐุงูƒุฑุฉ ูˆุณุฑุนุฉ ุงู„ู…ุนุงู„ุฌุฉ ู…ู‚ุงุฑู†ุฉ ุจุงู„ู…ุงุถูŠ.

๐ŸŒ€ Example

image.png

Assume we are searching for an element in an array, surely there will be an algorithm that performs the search operation. We may be lucky by finding the element at the beginning of the array, and this is called the best case.

If the element exists but happens to be located at the end of the array, this situation is called the worst case, because the algorithm needs to scan all elements before finding the target.

Sometimes, the element may be found somewhere in the middle of the array or may not exist at all; in such cases, we often refer to the average case, which represents the typical behavior of the algorithm for random inputs.

๐Ÿš€ Time Complexity and Big O Notation

๐Ÿš€ ุชุนู‚ูŠุฏ ุงู„ุฒู…ู† ูˆ Big O Notation

To determine which case we are currently facing (best, worst, or average), we need to understand Time Complexity.