This code
\documentclas{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tikz}
\begin{document}
\begin{figure}
\centering
\resizebox{.5\textwidth}{!}{
\fbox{
\begin{tikzpicture}[main/.style = {draw, circle}]
\node[main] (1) {$1$};
\node[main] (2) [above of=1] {$2$};
\node[main] (3) [right of=1] {$3$};
\node[main] (4) [right of=2] {$4$};
\node[main] (5) [right of=3] {$5$};
\node[main] (6) [right of=4] {$6$};
\draw[->] (1) edge node[midway, above, sloped] {\tiny 1} (2);
\draw[->] (2) edge node[midway, below, sloped] {\tiny 1-$\epsilon$} (3);
\draw[->] (2) edge node[midway, above, sloped] {\tiny 1} (4);
\draw[->] (3) edge node[midway, above, sloped] {\tiny 1} (4);
\draw[->] (4) edge node[midway, below, sloped] {\tiny 1-$\epsilon$} (5);
\draw[->] (4) edge node[midway, above, sloped] {\tiny 1} (6);
\draw[<->] (6) edge node[midway, above, sloped] {\tiny 1} (5);
\draw[->] (5) edge node[midway, below, sloped] {\tiny 1} (3);
\draw[->] (3) edge node[midway, below, sloped] {\tiny 1}(1);
\path[->] (6) edge[bend left=90, out=150, looseness = 2] node[midway, below, sloped] {\tiny 100} (1);
\end{tikzpicture} }
}
\caption{An example of nearest neighbor working poorly}
\label{tikz:NN_bad_sol}
\end{figure}
\end{document}
Yields this output
From what I could figure out, the problem is being caused by the last path. If I remove it, the picture is centered and has no whitespace. I don't understand how edge 6 -> 1 is creating so much whitespace

\begin{document}in your code. – SebGlav Jan 19 '23 at 18:47\clip (-1,-1) rectangle (3.5,1.8);on the beginning of yourtikzpicture. – SebGlav Jan 19 '23 at 18:54bboxcontain good explanation about problem you discussed in question – Zarko Jan 19 '23 at 19:17