# Binary search tree with a search path

> The nodes visited while searching for 6 are highlighted, along with the edges taken. A Trees example with its LaTeX source.

A Trees example in the TeXeR TikZ library: https://texer.org/library/trees/binary-search-path

Package: [Trees](https://texer.org/library/trees.md), on CTAN at https://ctan.org/pkg/pgf.

Tags: BST, binary search tree, search, data structure

## Source

```latex
\begin{tikzpicture}[
  level distance=12mm,
  level 1/.style={sibling distance=36mm},
  level 2/.style={sibling distance=18mm},
  level 3/.style={sibling distance=10mm},
  every node/.style={circle, draw, thick, minimum size=7mm, inner sep=0pt, font=\small},
  found/.style={fill=orange!25, draw=orange!85!black},
]
  \node[found] (root) {8}
  child { node[found] (a) {3}
    child { node {1} }
    child { node[found] (b) {6}
      child { node {4} }
      child { node {7} }
    }
  }
  child { node {10}
    child[missing]
    child { node {14}
      child { node {13} }
      child[missing]
    }
  };
  \draw[orange!85!black, very thick] (root) -- (a) -- (b);
\end{tikzpicture}
```

## As a complete document

The same example in a document that compiles on its own with pdfLaTeX:

```latex
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{tikzpicture}[
  level distance=12mm,
  level 1/.style={sibling distance=36mm},
  level 2/.style={sibling distance=18mm},
  level 3/.style={sibling distance=10mm},
  every node/.style={circle, draw, thick, minimum size=7mm, inner sep=0pt, font=\small},
  found/.style={fill=orange!25, draw=orange!85!black},
]
  \node[found] (root) {8}
  child { node[found] (a) {3}
    child { node {1} }
    child { node[found] (b) {6}
      child { node {4} }
      child { node {7} }
    }
  }
  child { node {10}
    child[missing]
    child { node {14}
      child { node {13} }
      child[missing]
    }
  };
  \draw[orange!85!black, very thick] (root) -- (a) -- (b);
\end{tikzpicture}
\end{document}
```
