1

I have a BTree made in TiKz in which I add a new element. Then the BTree has to be transformed. I would like to make it look like the example picture:

BTree with Insert

But I don't know how to achieve that? EDIT: I want to insert the arrow where the Rightarrow is in the example below

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}

\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{shapes}

\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\begin{document}

\begin{tikzpicture}
\tikzstyle{bplus}=[
    rectangle split, 
    rectangle split horizontal,
    rectangle split parts = 3, 
    draw
]
\tikzstyle{every node}=[bplus]
\tikzstyle{level 1}=[sibling distance=20mm]
\node {5 \nodepart{two} 6 \nodepart{three} 33}
;
\end{tikzpicture} $\Rightarrow$
\begin{tikzpicture}
\tikzstyle{bplus}=[
    rectangle split, 
    rectangle split horizontal,
    rectangle split parts = 3, 
    draw
]
\tikzstyle{every node}=[bplus]
\tikzstyle{level 1}=[sibling distance=20mm]
\node {5 \nodepart{two} 6 \nodepart{three} 33}
;
\end{tikzpicture}


\end{document}

Minimal BTree with Arrow

2
3

Two examples:

enter image description here

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz,
           diagrams={>=Straight Barb},
           nodes={text depth=0.25ex}
           }

\begin{document}
\begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]   
        &               \\ 
|[draw]| -5,-1,0 
    & |[draw]| 2 
        & |[draw]| 6,7,12 
\end{tikzcd} \begin{tikzcd}\ar[r,"\text{insert 3}",Rightarrow]&~\end{tikzcd}
    \begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2,3
        & |[draw]| 6,7,12
\end{tikzcd}

\bigskip 

\begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2
        & |[draw]| 6,7,12
\end{tikzcd} $\xRightarrow{\text{insert 3}}$
    \begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0

Is this what you like to achieve? Or should be arrow between nodes in bottom row?

enter image description here


\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage{tikz-cd}
\tikzcdset{arrow style=tikz,
           diagrams={>=Straight Barb},
           nodes={text depth=0.25ex},
           }

\begin{document}
\begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2
        & |[draw]| 6,7,12
\end{tikzcd} \begin{tikzcd} &   \\[5ex]
                            \ar[r,"\text{insert 3}",Rightarrow]&~\end{tikzcd}
    \begin{tikzcd}[column sep=tiny]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2,3
        & |[draw]| 6,7,12
\end{tikzcd}

\bigskip
\begin{tikzcd}[column sep=tiny,baseline={([yshift=1ex]current bounding box.south)}]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2
        & |[draw]| 6,7,12
\end{tikzcd} $\xRightarrow{\text{insert 3}}$
    \begin{tikzcd}[column sep=tiny,baseline={([yshift=1ex]current bounding box.south)}]
    & |[draw]| 1,5 \ar[ld]\ar[d]\ar[rd]
        &               \\
|[draw]| -5,-1,0
    & |[draw]| 2,3
        & |[draw]| 6,7,12
\end{tikzcd}
\end{document}
1

You can draw the trees with forest, and set the baseline for the multipart nodes.

\documentclass[11pt,a4paper]{article}
\usepackage{mathtools}
\usepackage[edges]{forest}
\usetikzlibrary{shapes.multipart}
\tikzset{bplus/.style={
    rectangle split, 
    rectangle split horizontal,
    rectangle split parts = #1, 
    draw
},bplus/.default=3}
\forestset{mtree/.style={for tree={draw,edge={-stealth}}}}
\begin{document}
$\vcenter{\hbox{\begin{forest}
  mtree
  [{1,5}
   [{-5,-1,0}]
   [{2}]
   [{6,7,12}]
  ]
\end{forest}}}\xRightarrow{\text{insert 3}}
\vcenter{\hbox{\begin{forest}
  mtree
  [{1,5}
   [{-5,-1,0}]
   [{2,3}]
   [{6,7,12}]
  ]
\end{forest}}}$
\bigskip

$\begin{tikzpicture}[baseline={(A.base)}]
\node[bplus](A){5 \nodepart{two} 6 \nodepart{three} 33};
\end{tikzpicture}\Longrightarrow
\begin{tikzpicture}[baseline={(B.base)}]
\node[bplus](B){5 \nodepart{two} 6 \nodepart{three} 33};
\end{tikzpicture}$
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.