Graphics, Figures & TablesTree Traversal Diagram

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sourlife
Posts: 2
Joined: Mon Jul 15, 2013 1:54 pm

Tree Traversal Diagram

Post by sourlife »

Dear community,

I'm having trouble drawing an Euler traversal of a tree. You can see an example of an Euler traversal on the picture on the corrsponding wiki page.

As an example, I have the following simple tree:

Code: Select all

\pstree{\Tc[name=n1]{3pt}\nput{90}{\pssucc}{$1$}}{%
  \Tc{name=n2]{3pt}\nput{270}{\pssucc}{$2$}%
  \Tc{name=n3]{3pt}\nput{270}{\pssucc}{$3$}%
}%
I would like to draw an Euler path around it. I tried to do something like this:

Code: Select all

\ncline[linestyle=dashed,offset=-5pt]{n1}{n2}
\ncline[linestyle=dashed,offset=5pt]{n1}{n2}
but have no idea on how to then connect the endpoints of these two lines in order to make an arc below node 2.

I thought that one solution would be to somehow declare a new node at these two endpoints. That would make it easy then by using the \nccurve command, but I do not know how to declare new nodes for these endpoints.

Another problem of course is the second \ncline. Its starting point should actually be below the root node (node 1), so that I can continue from that point to the other node (node 3).

Does anyone have a solution or an example of how to draw tours or point me to the right direction how to do it?

Thank you!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

dicker2
Posts: 4
Joined: Wed May 29, 2013 11:29 am

Tree Traversal Diagram

Post by dicker2 »

Hello,

have you taken a look at tikz-qtree? It makes tree building slightly easier and allows e.g. lines between nodes. The tikz-qtree manual on page 6 shows something remotely similar to what you want to do.

If all fails, draw it manually in Inkscape?

Best wishes
Post Reply