"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > BIG OR - PYTHON

BIG OR - PYTHON

Published on 2025-02-05
Browse:100

1. Definition

Mathematical notation that describes the upper limit of execution time or the use of an algorithm space. It is denoted as or (f (n)) , where f (n) is a function that represents time or space depending on the input size n .

Notación Big O - Python
2. Purpose

    Algorithms comparison
  • : Allows you to compare different algorithms and choose the most efficient for a given problem. Scalability
  • : It helps predict how an algorithm will behave when the amount of data increases.
  • 3. Complexity analysis

Worse case

: Refers to the scenario where the algorithm takes longer or uses more resources. Big or generally refers to this case.
  • Better case and average case : Although they are important, they are used less frequently for the Big O.
  • 4. Space vs. Time

Temporary complexity

: It refers to the time it takes for an algorithm to execute. [
  • Spatial complexity : refers to the amount of additional memory you use. You can have notations such as or (1)
  • (constant space) or
  • (linear space). Example: Import Timeit IMPORT MATPLOTLIB.PYPLOT AS PLT Import CProfile # O (1) Def Constant_time_operation (): return 42 # O (log n) Def logarithmic_time_operation (n): Count = 0 While N> 1: N // = 2 Count = 1 return count # Or (n) def linear_time_operation (n): Total = 0 for i in range (n): Total = i Total return # O (n log n) def linear_logarithmic_time_operation (n): if n

Thank you for reading !!
Apóy me reacting and opinioning.

            
Release Statement This article is reproduced at: https://dev.to/stevenhdz/notacion-big-o-1omml?1 If there is any infringement, please contact [email protected] to delete it.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3