我正在嘗試做一些類似於 CLRS 中的合併圖的事情

我正在嘗試做一些類似於 CLRS 中的合併圖的事情

抱歉,這不是最佳解決方案。它不必是精確的。只是尋找建議。 合併

答案1

這種樹可以用 來生產forest

\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={draw,fill=gray!20,s sep+=6ex,l sep+=2ex,math content,
edge={stealth-,very thick,shorten >=3pt,shorten <=3pt},
where n children={0}{}{label={[yshift=-2.5ex,font=\small\sffamily]below:merge}}}
[{1~~2~~2~~3~~4~~5~~6~~6}
 [{2~~4~~5~~6}
  [{2~~5}
   [5]
   [2]
  ]
  [{4~~6}
   [4]
   [6]
  ]
 ]
 [{1~~2~~3~~6}
  [{1~~3}
   [1]
   [3]
  ]
  [{2~~6}
   [2]
   [6]
  ]
 ]
]
\path (current bounding box.north) node[above=0.5ex] {sorted sequence}
(current bounding box.south) node[below=0.5ex] {initial sequence};
\end{forest}
\end{document}

在此輸入影像描述

相關內容