From the course: Python: Programming Efficiently

Unlock the full course today

Join today to access over 23,300 courses taught by industry experts.

Algorithm complexity

Algorithm complexity

- Let's talk about the complexity of algorithms and how it affects their run time. So far, we have discussed how we can optimize the implementation of a given algorithm for the Mandelbrot set. We had NamPy and number take care of the complex arithmetic instead of doing it in pure Python where every individual operation is slower. In some cases, we may have a choice among multiple algorithms that give the same output by use of different number of operations. The classic examples, are the algorithms to sort a list. A simple Insertion sort grows a sorted list of elements by inserting them one by one in the right spot for a list of length, n we need n squared operations. So we'd say that the algorithm has ordered n squared time complexity or its big goal n squared. Smarter algorithms such as Quicksort require a number of operations proportional to n times the logarithm of n So that algorithm has order n times log n time…

Contents