Questions tagged [trees]

For questions about tree graphs, or about tree data structures.

Filter by
Sorted by
Tagged with
3 votes
1 answer
58 views

Percent symbol with FontFamily setting looks weird in Dendrogram

Bug introduced in 12.3.1 or earlier, persisting through 13.3.1. ...
Y. zeng's user avatar
  • 425
2 votes
2 answers
107 views

How can I make the output of Reduce more readable (with a tree)?

Oftentimes, the output of Reduce is quite difficult to read because it has too many && and ...
ions me's user avatar
  • 751
3 votes
3 answers
400 views

Better way to do such iteration

Consider such an iteration function ...
matrix42's user avatar
  • 6,744
2 votes
0 answers
74 views

Make Tree output wider?

I use Tree and what I have in the nodes is somewhat larger output (horizontally). That means the nodes are displayed with a lot of overlap. Is there a way to make the "outgoing" edges to the ...
Andreas Lauschke's user avatar
6 votes
1 answer
153 views

How can I make the vertices of a tree graph clickable?

Would it be possible to make the vertices of a tree graph clickable, executing a function when clicked? Specifically, I am using Mathematica / the Wolfram Language to prototype a modern, microtonal ...
Frank O'Neill's user avatar
2 votes
1 answer
78 views

Visualizing order of operations

TreeForm[HoldForm[ (9-2^2+10 8)/9]] produces this: Is there a way to use Divide instead of ...
Geremia's user avatar
  • 478
1 vote
2 answers
118 views

Display Binary Tree as Centred Array

I would like to display a binary tree using something analogous to TableForm. For example, a small such tree is given by this array (which except for the root still ...
pdini's user avatar
  • 475
3 votes
2 answers
276 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. ...
Najib Idrissi's user avatar
1 vote
0 answers
27 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. ...
user5601's user avatar
  • 3,561
8 votes
4 answers
496 views

How to get all nodes in Tree?

What is the most efficient way to get the nodes of a Tree? ...
M.R.'s user avatar
  • 31k
5 votes
2 answers
351 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: ...
B flat's user avatar
  • 5,377
7 votes
1 answer
129 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 ...
我心永恒's user avatar
  • 1,382
0 votes
1 answer
49 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!
Lawrence's user avatar
0 votes
1 answer
62 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?
Peter Burbery's user avatar
0 votes
0 answers
66 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 ...
ions me's user avatar
  • 751
0 votes
0 answers
36 views

FindSpanningTree not working properly on directed graph with negative weights

The code: ...
user3257842's user avatar
1 vote
2 answers
117 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 ...
user3257842's user avatar
2 votes
2 answers
150 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 ...
expression's user avatar
  • 5,562
4 votes
2 answers
134 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 ...
Gustavo Delfino's user avatar
8 votes
0 answers
249 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 ...
M.R.'s user avatar
  • 31k
10 votes
5 answers
620 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 ...
High Performance Mark's user avatar
0 votes
1 answer
131 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: ...
user57467's user avatar
  • 2,304
0 votes
1 answer
100 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 ...
gete's user avatar
  • 21
13 votes
1 answer
263 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 ...
Slepecky Mamut's user avatar
3 votes
3 answers
939 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 ...
Mubarak Alsaeedi's user avatar
4 votes
1 answer
246 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 ...
Kiril Danilchenko's user avatar
2 votes
1 answer
71 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: ...
Red Banana's user avatar
  • 5,121
3 votes
0 answers
118 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 ...
Red Banana's user avatar
  • 5,121
2 votes
1 answer
47 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 ...
florin's user avatar
  • 1,582
6 votes
5 answers
498 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. ...
matrix42's user avatar
  • 6,744
5 votes
1 answer
162 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 ...
KBL's user avatar
  • 623
1 vote
1 answer
35 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 ...
David's user avatar
  • 93
4 votes
1 answer
150 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 ...
Madeline Brandt's user avatar
5 votes
2 answers
100 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 ...
faceclean's user avatar
  • 1,291
1 vote
1 answer
170 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 ...
Mwen Rele's user avatar
0 votes
0 answers
147 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 ...
Vojtevo's user avatar
  • 63
17 votes
2 answers
1k views

How to draw a "proper" tree diagram

...
CasperYC's user avatar
  • 1,460
4 votes
1 answer
75 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, ...
Pillsy's user avatar
  • 18.2k
2 votes
1 answer
162 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 ...
Arjihad's user avatar
  • 1,134
6 votes
1 answer
168 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 ...
Fernando Martin's user avatar
1 vote
1 answer
428 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 ...
Student's user avatar
  • 111
5 votes
1 answer
182 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 ...
JHarris's user avatar
  • 51
4 votes
3 answers
151 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 ...
Sam B's user avatar
  • 159
4 votes
2 answers
94 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 ...
amator2357's user avatar
  • 1,284
4 votes
2 answers
96 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 ...
amator2357's user avatar
  • 1,284
7 votes
3 answers
446 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 ...
amator2357's user avatar
  • 1,284
10 votes
2 answers
284 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 ...
Ren Witcher's user avatar
13 votes
6 answers
276 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 <...
Roman's user avatar
  • 44.9k
6 votes
2 answers
411 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: ...
user13892's user avatar
  • 8,973
1 vote
1 answer
55 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 ...
StarBucK's user avatar
  • 2,114