Questions tagged [trees]
For questions about tree graphs, or about tree data structures.
132
questions
3
votes
2
answers
229
views
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. ...
1
vote
0
answers
22
views
TreePosition with multiple (not just node data) conditions
Given a Tree object, TreePosition takes patterns only on the "data" of the node plus a level spec.
...
8
votes
4
answers
240
views
How to get all nodes in Tree?
What is the most efficient way to get the nodes of a Tree?
...
5
votes
2
answers
281
views
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:
...
6
votes
1
answer
77
views
How to change TreeForm style?
I use
t = ArrayReshape[Range@12, {2, 2, 3}];
t // TreeForm
get "TreeForm" ,like this
I want to make a change to the "TreeForm",like this:
I ...
0
votes
1
answer
48
views
Why level 1,-1,2,3 in a data set containing 10 real numbers are the same? As shown in the following figure! [closed]
Why level 1,-1,2,3 in a data set containing 10 real numbers are the same? As shown in the following figure!
0
votes
1
answer
58
views
How to find all functions that accept level specifications as an argument?
How can I find a list of every function that takes a level specification as an argument?
0
votes
0
answers
42
views
How to find all the tree leaves of an expression?
I'd like to better understand what mathematica is doing during simplification, so I tried expression //TreeForm //TreeLeaves to see what it's picking up on.
Except ...
0
votes
0
answers
30
views
1
vote
2
answers
67
views
Is there a way to make FindSpanningTree return a directed graph?
I would like to use edge-direction to distinguish between parents and children in a given spanning tree. When choice of root-node is not unique FindSpanningTree ...
2
votes
2
answers
85
views
According to the path, how to draw such a binary tree?
As shown in the figure, the path can be generated by the following code
...
4
votes
2
answers
130
views
Preventing truncation of trees
In regards to the new tree functionality in Mathematica 12.3, apparently the display is collapsed/summarized when an element has more than 10 sub-elements, so what I was expecting to be displayed as ...
8
votes
0
answers
243
views
Improving label collisions for Tree/Graph?
Historically, MMA has never handled label collisions well, but recently they added some improvements here via things like Callout. I want to fix ImageSize but still ...
10
votes
5
answers
534
views
How to construct a tree from a preorder traversal
The list
t1 = {1, 2, 3, 3, 4, 4, 3, 3, 4, 3, 3, 2, 3, 4, 2, 3, 2};
might be derived from a pre-order traversal of
...
0
votes
1
answer
57
views
Add list of vectors to list of vectors recursively
This question relates to Add a vector to a list of vectors whereas here I want to add list of vectors to list of vectors recursively.
Given:
...
0
votes
1
answer
67
views
How to generate a graph and determine its maximum spanning tree in Wolfram Mathematica? [closed]
I have just started learning Mathematica. I am trying to generate the following edge labeled graph $G$, and its maximum spanning tree using Wolfram Mathematica.
Note. A maximum spanning tree is a ...
11
votes
1
answer
222
views
How to draw the tree in a "pitchfork" form?
How to set the options or other parameters in a TreePlot to draw the branching outside of the vertex? I.e. in a form similar to a dendrogram (but the dendrogram plot itself does not support the ...
3
votes
3
answers
527
views
Find all spanning tree in a given graph
Is there a way I can generate all the spanning tree in the following graph:
Also, is there a way to insert the adjacency matrix, then I get an output of all possible spanning trees?
The adjacency ...
3
votes
1
answer
171
views
Find all non-isomorphic trees with $n$ nodes
I would like to compute all non-isomorphic trees with n nodes efficiently. I use the following approach: I create all possible trees ( Visualizing Cayley's Formula in Mathematica) and filter the ...
2
votes
1
answer
51
views
How do I reference a string as the root node of a graph?
I've produced the following tree plot:
But I want the root to be $a$, which is a string. I looked at the documentation, it says:
So it seems it's very easy, we just write something like:
...
3
votes
0
answers
83
views
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 ...
2
votes
1
answer
45
views
A simple way to create graphs of series and parallel networks?
I tried
TreePlot[{{G -> M, "p1"}, {M -> D, "p2"}}, Left,
VertexLabeling -> True]
I was hoping the graph would look like a horizontal ...
6
votes
5
answers
342
views
Construct a permutation tree plot
How to construct a tree like this? I was looking CompleteKaryTree initially, there are some similarities overall, but it's still different.
...
5
votes
1
answer
151
views
Visualizing directories--a cleaner view of a helpful older post
I am looking to make graphics of a folder hierarchy, and this old post was very helpful. However, this method gives the whole file path for each node, which makes a complete mess in the directory I ...
1
vote
1
answer
28
views
InputField and TreeForm problem
I want to use the expression enter by the user and form the Tree,
so I did TreeForm[test] as the picture show but it's not working.
But if I do it manually, it works.
Can anyone explain to me why ...
4
votes
1
answer
104
views
Compute all trees on a given label set
Given a set of labels {a_1,...,a_n} (with some labels possibly appearing multiple times) I would like to efficiently compute all trees with n leaves labelled {a_1,...,a_n} and 2n-2 nodes. This is ...
5
votes
2
answers
73
views
How to draw a tree in which each vertex contains some circles inside?
I would like to recreate the following picture in Mathematica. I know how to draw a tree with GraphLayout. But I don't know how to create the shape of nodes as below. A bit hints about where to start ...
1
vote
1
answer
106
views
Construct a binary tree where nodes are labeled according to given rule
I want to plot a binary tree in Mathematica where the nodes are labeled according to a given rule. In fact, whether a node has a left child or a right child or both, will be determined by a rule. And ...
0
votes
0
answers
106
views
Is a tree structure possible in Mathematica?
Let's say I have a vector,
vector={1,2,3,4,5,6,7};
and I want to use its items as leaf nodes in a tree datasctructure, then work with them as such, adding new ...
17
votes
2
answers
1k
views
4
votes
1
answer
69
views
How do I build a position index of a general held expression to arbitrary depth?
I have an expression which I would like to make a position index of, which for sake of argument will be this:
expr = f[q + g[x, y, z]];
Since it's not a list, ...
2
votes
1
answer
102
views
Visualize tree with many children per node
I have some data that I would like to visualize as a tree. It contains the parent node and its children. I already looked up TreeForm and TreeGraph but the problem is, that my parent node got about 80 ...
6
votes
1
answer
166
views
How can I make TreeForm think some elements are atomic?
I want to apply TreeForm to some expressions of the form m[m[m[y[1], y[1]], x[1]], z], but I want Mathematica to treat ...
1
vote
1
answer
347
views
How to construct a specific binary tree from a particular set of information?
I run a algorithm to solve a problem that return a set of information relative to a binary tree associated with these problem. For illustrate the results obtained I try to plot the binary tree. I make ...
5
votes
1
answer
143
views
Steiner Tree Approximation
I am wondering about the existence of Mathematica code to find (approximate) Steiner trees in graphs. I know there are a number of algorithms to do so --- just curious if anyone has implemented any ...
4
votes
3
answers
127
views
Set the parent of each child while iterating over a List
I'm still new to this language and have tried a number of ways with no success. I have a list of keys with values. These values are used to identify the parent of the current item. The list is ...
4
votes
2
answers
76
views
Issue with displaying a tree graph after deleting a vertex
Say, I have an expression tree:
g = IGExpressionTree[ {{{1,2},{{3,4},{5,6}}},7}, VertexLabels -> "Name"]
From that tree I want to delete all the vertices ...
4
votes
2
answers
92
views
Adding edges to a TreeForm of an expression
Say I have an expression {1,{{2,3},4}}. It's TreeForm looks as follows:
{1,{{2,3},4}} //TreeForm
Now, on each level of that ...
7
votes
3
answers
395
views
TreeGraph construction
I have a list l={{1,1},{2,3},{2,3,2,3,4}}. Based on that list, I want to draw a tree. Starting from a single point at the top of a tree, I proceed as follows, using ...
10
votes
2
answers
260
views
How to explain the behaviour of TreeForm? [duplicate]
Just try this:
g=1;a=1;TreeForm[Hold[g[a]]]
The weird thing in the outcome is that the node of g displays 1 ,and a is still a.
I do not know how to explain ...
13
votes
6
answers
266
views
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
I have an arbitrary ragged nested list-of-lists (a tree) like
A = {{a, b}, {c, d}, {{{e, f, g, h, i}, {j, k, l}}, m}, n};
Its structure is given by the rules
<...
6
votes
2
answers
388
views
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:
...
1
vote
1
answer
43
views
Head of level : question about the Apply function
I am not sure to really understand how the function Apply works at level 2 for example.
I have read this question and few others and it doesn't help me :Levels: how do they work?
Take the following ...
3
votes
0
answers
2k
views
Semantic tableaux generator
I would like to use Mathematica to automatically generate a semantic tableaux (truth tree) from a formula in propositional logic).
Here is an example formula:
$$(a \lor\lnot b )\land b$$
Here is ...
1
vote
3
answers
209
views
How to randomly generate Tree or Nested List of Function in Mathematica?
In detail,
I want to generate randomly something like
Divide[Add[X,Times[X,Y]],Times[X,3]]
or
{Divide,{Add,X,{Times{X,Y}}},{Times,X,3}}
(Specified Function(# of argument is from 2 to 5)) + ...
29
votes
5
answers
2k
views
Elegant implementation of factorial tree graph
Consider the tree graph used in part of my solution to this question:
Each level $i$ has $i!$ nodes, and the branching ratio is $i+1$:
I kludged together code to generate this graph (with code ...
8
votes
3
answers
226
views
How to connect all points in a graph generated by a set of given vertexes?
I am trying to construct a tree by looking at the nearest neighbors (or just approximately nearest for higher efficient) of a set of given vertexes. I first try this:-
...
1
vote
2
answers
291
views
How can I extract weights labelling edges starting from a fixed set of vertices
Let g be a directed weighted graph (in particular is tree). Given a set of vertices A, how can I extract the weights in a set <...
2
votes
2
answers
90
views
paths in a weighted directed trees
Given an weighted directed tree, I have to write this:
Given a vertex v, I should list all the vertex c such that there exist ...
6
votes
4
answers
356
views
How can I create an Association from a multidimensional list of values and a list of keys?
Given a list of values such as
vals = {{{{0., 633.25}, {642.96, 677.34}}, {{591.56, 632.45}, {634.9, 715.6}}}}
and a list of "Dimensions" such as
...