I am looking for graphs of big-o notation terms below;
- O(1) is a constant time complexity
- O(n) is a linear time complexity
- O(log_2(n)) is a logarithmic time complexity (I mean log basis 2)
- O(n log_2(n))
- O(n^2) is a quadratic time complexity
- O(n^3) cubic time complexity
- O(2^n) exponential time complexity
Could you help me to represent these big O notations using pgfplots?
I have tried this code snipped for log_2(n). To tell the truth, I'm not so sure.
\documentclass[border=50pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[trim axis left]
\begin{axis}
[
axis lines = left,
xlabel = \(n\),
ylabel = {\(\log_{2}(n)\)},
]
[domain=0:10,
samples=1000,
enlarge x limits=false,
grid=both,
no markers,
axis equal,
legend pos=outer north east,
legend style={draw=none},]
\addplot +[thick] {ln(x)/ln(2)};
\addlegendentry{$\log_{2}(n)$};
\end{axis}
\end{tikzpicture}
\end{document}