For questions about tree graphs, or about tree data structures.
Questions tagged [trees]
143 questions
8
votes
4 answers
How to get all nodes in Tree?
What is the most efficient way to get the nodes of a Tree?
tree = Tree[1, {Tree[ 2, {Tree[5, {Tree[12, None], Tree[13, None]}], Tree[6, None]}], Tree[3, {Tree[7, {Tree[14, None], Tree[15, None], Tree[16, None]}], Tree[8, None], Tree[9,…
M.R.
- 31,425
- 8
- 90
- 281
6
votes
2 answers
Is there a way to draw a level tree?
Consider the following expression.
expr = {a, {b1, b2}, {c, {d1, d2}}};
One can get the levels in an expression as follows:
ClearAll[levels];
SetAttributes[levels, {HoldAllComplete}];
levels[expr_] :=
Column @ Table[Level[expr, {level}, Heads ->…
user13892
- 9,375
- 1
- 13
- 41
5
votes
2 answers
Simple Decision Tree for Tuples
I would like to create a simple decision tree for a 3-course meal that looks something like the following:
The tuples can be created using the code:
Tuples[{{""}, {"Soup", "Salad"}, {"Chicken", "Patty", "Liver",
"Beef"}, {"C", "IC"}}]
to…
B flat
- 5,523
- 2
- 14
- 36
4
votes
1 answer
ExpressionTree issues
I can't see what I'm doing wrong in the following - I'd like to import some XML as a Tree (for structure visualisation) and convert it to an Association for querying content:
xtree = ExpressionTree[Import["ExampleData/paintings.xml"], "XML"]
Which…
EstabanW
- 700
- 1
- 4
- 11
3
votes
2 answers
TreePlot Vertex Labelling
I have plot:
TreePlot[{1 -> 4, 1 -> 6, 1 -> 8, 2 -> 6, 3 -> 8, 4 -> 5, 7 -> 8},
VertexLabeling -> True]
Can the labeling on the second level be done as 8, 6 ,4 while keeping the command vertex order unchanged (Background :I rotated the tree on…
TraceKira
- 363
- 1
- 8
3
votes
2 answers
How to display a tree with a root at the bottom but leaves in left-to-right order?
With the Tree function, I can draw arbitrary trees:
Tree[f, {1, 2, 3}]
However, real trees grow from the ground to the sky. When I pass the TreeLayout -> Bottom option, the leaves become in the wrong order:
How can I make leaves appear in the…
Najib Idrissi
- 576
- 3
- 11
3
votes
0 answers
How to "program in binary trees" with Mathematica?
I want to do the following:
f[x_] := If[OddQ[x[[1]]], Nothing, x/2 // Simplify]
A = Table[2 (n + k), {k, 0, 4}]/2
n = 2 n1;
f /@ A
n = 2 n1 + 1;
f /@ A
This outputs the following:
{n, 1 + n, 2 + n, 3 + n, 4 + n}
{n1, 1 + n1, 2 + n1}
{1 + n1, 2 +…
Red Banana
- 5,329
- 2
- 29
- 47
3
votes
2 answers
Depth first scan of a tree backwards
How can I traverse this tree, to get a sequence of vertices {8,4,2,9,5,1,6,3,7}? I've failed to produce it with DepthFirstScan, does this particular order even has a name?
TreeGraph[{1->2,1->3,2->4,2->5,3->6,3->7,4->8,5->9}, VertexLabels ->…
swish
- 7,881
- 26
- 48
2
votes
2 answers
Create a Figure with a sequence of Balanced Binary Trees
I would like make the attached image by Mathematica.
someone who could help me?
Thank!
user15850
- 97
- 3
2
votes
2 answers
How to make Huffman coding by using tree representation
I want to make Huffman coding with Mathematica. I saw a demonstration, but it is not the thing I want to make. I want to show the tree for given string.
Here is an example picture:
You can see the demonstration from here. This demonstration looks…
forumcash
- 557
- 5
- 14
2
votes
2 answers
How do I create a recursive tree plot for the Fibonacci sequence?
I would like to create a plot that shows the recursive tree for the nth number of the fibonacci sequence, as the one below.
http://faculty.ycp.edu/~dhovemey/fall2005/cs102/lecture/fib5.png
Ideally, I want to call a function that changes the tree for…
rajann
- 21
- 1
- 3
0
votes
1 answer
how to move the root from a tree?
I have the code :
myVertexes = {"xxx", "yyy", "Block3", "p5", "Block2",
"Block1", "p3", "p2", "p1"};
myVertexLabels =
Table[myVertexes[[i]] ->
Placed[Rotate[
Panel[myVertexes[[i]],
Background ->
…
TraceKira
- 363
- 1
- 8
0
votes
1 answer
Is it possible to mark a Tree node and path to it?
I have the Tree :
TreeForm[Criminals["cat" , "dog", "human"["killer", "thug", "macho"]],
DirectedEdges -> True,
VertexRenderingFunction -> (Inset[
Panel@Rotate[#2, -\[Pi]/2], #1] &)] // Rotate[#, \[Pi]/2] &
Is it possible to mark node…
TraceKira
- 363
- 1
- 8
0
votes
2 answers
TreePlot remove an arrow
Is it possible to make Mathematica make a connection to p2 from both SysVar 2 and SysVar3 like I drawn ?
Code:
listNodesSubsystemView = Join[{ "xxx" -> "SubSystems"},
Reverse[{"SubSystems" -> "SysVar1", "SubSystems" -> "SysVar2",
…
TraceKira
- 363
- 1
- 8
0
votes
1 answer
Why level 1,-1,2,3 in a data set containing 10 real numbers are the same? As shown in the following figure!
Why level 1,-1,2,3 in a data set containing 10 real numbers are the same? As shown in the following figure!
Lawrence
- 29
- 2