Questions tagged [trees]

For questions about the data structures known as trees.

Filter by
Sorted by
Tagged with
4
votes
1answer
54 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, ...
0
votes
0answers
25 views

Exhaustive search by using a tree without specifying all the nodes

I'm trying to draw a tree to visualize an exhaustive search without specifying all the nodes' positions in the graph. For example, I'd like to build a tree so that, given n=4 objects, the nodes with ...
2
votes
1answer
60 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
1answer
157 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
1answer
121 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 ...
4
votes
0answers
67 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
3answers
118 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 ...
3
votes
2answers
60 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
2answers
75 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
3answers
312 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 ...
1
vote
0answers
57 views

Segment tree implementation

I want to implement a segment tree visualization. I was looked for implementation in WL but didn't find. Before I'm implementing it by myself, maybe anyone knows about some implementation that will be ...
10
votes
2answers
216 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 ...
0
votes
0answers
33 views

How to represent nodes in a probability tree

I was trying to investigate the following problem I made up: A bag contains n distinctly coloured marbles. A marble is drawn at random. It is replaced and a second identical marble of the same colour ...
13
votes
6answers
248 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
2answers
343 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
1answer
35 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
0answers
393 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
3answers
144 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)) + ...
30
votes
5answers
1k 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
3answers
144 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
2answers
147 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
2answers
79 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 ...
5
votes
4answers
249 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 ...
6
votes
2answers
457 views

How to make a Tree diagram using images as vertices, that goes left to right

In Graph or TreeGraph, I can make the vertices images, but the tree always starts at the top. ...
-1
votes
1answer
81 views

Create a network using data?

I'm looking to make a network visualization of a list of data values. The list is formatted as so: $DataList = ((a_1, b_1, c_1, d_1,), (a_2, b_2, c_3, d_3), (a_3, b_3, c_3, d_3),...(a_n, b_n, c_n, d_n)...
4
votes
1answer
266 views

Lineage tree plots

I am trying to plot a lineage tree, for example: This plot represents a population of dividing cells. Each horizontal line is the lifetime of a single cell, until division. When it divides, the line ...
3
votes
2answers
144 views

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, ...
1
vote
0answers
28 views

Strange shaking of the output of TreeForm [duplicate]

When I execute the following: TreeForm[Hold[Plus[1, 2]]] I get the expected output. But when I execute ...
2
votes
1answer
62 views

Problem with TreeForm

I am having an issue with the command TreeForm. Suppose I have a list L of lists I would like to apply ...
11
votes
5answers
1k views

Can trees be made into graphs?

When one has the output of a function like TreeForm, for instance: Can this be turned into a Graph object? I would like to be able to apply functions like ...
6
votes
1answer
138 views

How to efficiently compute all trees with n leaves and 2n-2 nodes

I would like to efficiently compute all trees with n leaves and 2n-2 nodes. This is equivalent to trees with n leaves where all interior (non-leaf) vertices are trivalent. The input should be the ...
7
votes
1answer
111 views

How to stop TreeForm from shaking when changing resolution?

Update (original question below kept as is). I can reproduce this on version 11.1.1 on windows 7 as well as 11.0.1. (restarted Mathematica). Interesting is that it only shows on 125% resolution. ...
2
votes
1answer
143 views

How to display a function's definition in TreeForm?

I want to use TreeForm to analyse functions. I come up with two methods to do it. The first one is preferred, but it doesn't work as expected. The second one is just a workaround. I don't know why the ...
0
votes
2answers
131 views

How to convert a tree in a list? [closed]

I have a Tree representing a list, and I would like to plot this list. Unfortunately when I try to listplot my tree mathematica doesn't plot anything. So, I would like to convert my tree into the ...
2
votes
3answers
308 views

How to customize labels in TreePlot?

I want to specify the labels attached to vertices in TreePlot, allowing distinct vertices to carry the same label. The following attempt fails: ...
12
votes
3answers
403 views

Combinatorica Functionality in Vers. 11.1.1

Since version 10, much of the original functionality in the Combinatorica package has been subsumed (consumed?) by new graph primitive functions. However, as per similar posts, at times there are ...
7
votes
3answers
285 views

Construct symmetric binary tree plot

I want to create a plot that looks like the following: In essence, it is a symmetric plot with binary splits. I am a Mathematica novice and don't know how to do it. I need to be able to set the ...
5
votes
2answers
138 views

Rule-based branching construction of lists

I would like to efficiently construct all lists subject to certain relations. For example, I have the following "root objects" and rules: ...
7
votes
1answer
277 views

How to perform a depth-first in-order traversal of an expression?

To complement my earlier questions: How to perform a breadth-first traversal of an expression? How to perform a depth-first preorder traversal of an expression? I would now like to ask: how to ...
1
vote
0answers
129 views

How does pattern matching in expression work?

I have been trying to understand how mathematica does pattern matching: {Sin[x] + 1} /. Sin -> Cos returns Cos[x] + 1 ...
5
votes
2answers
112 views

Cost of the minimal spanning tree

I can create a grid graph with a random weights of edges and compute its minimal spanning tree by: ...
20
votes
2answers
571 views

Collapsible Tree

Has somebody tried to program for data visualization an interactive Collapsible Tree like shown here: http://bl.ocks.org/mbostock/4339083. This implements the Reingold-Tilford algorithm. ...
1
vote
1answer
77 views

A Condorcet winner tree

I want to model a random tournament. Say that there are four candidates to simplify. I want to construct a tree with vertices depending on the result. For instance, if $a$ encounters $b$ and $a$ wins,...
5
votes
2answers
795 views

How to really plot a binary tree?

A binary tree is one that distinguishes left child from right child. However, in TreePlot you cannot specify which child is left, which is right, so the output is not a binary-looking tree. For ...
13
votes
1answer
778 views

TreePlot does not give a “binary-looking” tree for a binary tree

I use the following code to generate a binary tree with root 1. ...
18
votes
2answers
585 views

Cone Trees: map a graph onto geometric shape

Question Is it possible to map a Graph onto a geometric object such as a Cone? Motivation Visualizing large trees can be ...
17
votes
1answer
1k views

How to work with phylogenetic trees?

A phylogenetic tree can be represented as a comma-bracket string by the Newick format (see the Newick Standard, or this site for syntax details; here is an online tree visualizer). A simple Newick ...
13
votes
1answer
202 views

TreeForm outputs different results for the same input, Why?

Bug introduced in 8.0.4 or earlier and persisting through 11.0.1 First of all, please look at the below inputs and outputs: ...
1
vote
2answers
1k views

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, ...
7
votes
1answer
171 views

Minimal Spanning Tree with EdgeWeights

Given a graph with EdgeWeights, I'm finding the minimal spanning tree: ...