Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case scenario, and can be used to describe the execution time required or the space used (e.g. in memory or on disk) by an algorithm.
The best way to understand Big O thoroughly was to produce some examples in code:
O(1) describes an algorithm that will always execute in the same time (or space) regardless of the size of the input data set.
bool IsFirstElementNull(IList<String> elements)
{
return elements[0] == null;
}
O(N) describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set. The example below also demonstrates how Big O favours the worst-case performance scenario; a matching string could be found during any iteration of the for loop and the function would return early, but Big O notation will always assume the upper limit where the algorithm will perform the maximum number of iterations.
bool ContainsValue(IEnumerable
bool ContainsDuplicates(IList
if (elements[outer] == elements[inner]) return true;
}
}
return false; } 4. O(2^N) denotes an algorithm whose growth doubles with each addition to the input data set. The growth curve of an O(2^N) function is exponential — starting off very shallow, then rising meteorically. An example of an O(2^N) function is the recursive calculation of Fibonacci numbers:
int Fibonacci(int number) { if (number <= 1) return number;
return Fibonacci(number - 2) + Fibonacci(number - 1); }
Logarithms are slightly trickier to explain so I’ll use a common example binary search
A grasp of Big O is an important tool when dealing with algorithms that need to operate at scale, allowing you to make the correct choices and acknowledge trade-offs when working with different data sets.
how can you decide what is the best of performance
How to Setup an Awesome Python Environment for Data Science or Anything Else
Let’s get started with the most important thing when working with python: the interpreter. For sure you could just simply download and install your favorite version of python and put everything into that. But what if you have programs that require different python versions or programs that depend on different versions of the same third-party module and you want to switch between those programs seamlessly? Pyenv will help you doing that! Pyenv is a set of three tools, from which I present two here, that are pyenv (used to install python) and pyenv-virtualenv (used to configure your global tools). You can install them by curl https://pyenv.run | bash After that, add the following lines to your .bashrc (same for .zshrc) to have pyenv available in your terminal export PATH=”~/.pyenv/bin:$PATH” eval “$(pyenv init -)” eval “$(pyenv virtualenv-init -)” and finally, restart your terminal. Now, you can use pyenv to install almost any python interpreter, including pypy, and anaconda. Note, that pyenv builds python locally on your machine. Building python requires several libraries. On my Ubuntu machine, I have to install the following ones to not run into problems sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev openssl libgdbm-dev libgdbm-compat-dev liblzma-dev libreadline-dev libncursesw5-dev libffi-dev uuid-dev Now, to install a python interpreter just do pyenv install VERSION_YOU_WOULD_LIKE_TO_INSTALL You can list out all versions available via pyenv pyenv install –list To make it concrete, let’s install python 3.7.5 and make it your default global-interpreter pyenv install 3.7.5 pyenv global 3.7.5 When you type python — version you should get back Python 3.7.5