Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [trees]

For questions about the data structures known as trees.

3
votes
2answers
52 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
63 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
277 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 ...
0
votes
0answers
31 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 ...
8
votes
2answers
181 views

How to explain the behaviour of TreeForm?

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
26 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
235 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
317 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
28 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
156 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
102 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
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
120 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
104 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
73 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
203 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
422 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
76 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
211 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
113 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
60 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
107 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
109 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
135 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
120 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
217 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
370 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
254 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
132 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
201 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
123 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
105 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: ...
19
votes
2answers
513 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
74 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
648 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
752 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. ...
17
votes
2answers
550 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 ...
16
votes
1answer
824 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
197 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
151 views

Minimal Spanning Tree with EdgeWeights

Given a graph with EdgeWeights, I'm finding the minimal spanning tree: ...
7
votes
1answer
61 views

KaryTree of Text .csv and Correlation

How can I make a KaryTree of this raw-data (raw-data at the end of the question): This is is data from a political survey in which I ask 5 questions with the following possible answers: Q1: 'Y'= Yes,...
2
votes
2answers
141 views

VertexDelete Problem

I am doing a straightforward deletion of a set of vertices in a Tree using Mathematica. ...
8
votes
1answer
314 views

How to construct a tree from a notebook?

Given the notebook itself we can think of it as a tree graph: the root vertex is the empty notebook itself, the headers of cell groups are vertices, and all other cells as leaf vertices. I'd like to ...
7
votes
3answers
176 views

Conditional tree vertex rendering?

I use the following code to plot a binary tree ...
2
votes
2answers
107 views

Merge two trees into a rectangular matrix in Mathematica

How can I merge two trees, t and s, so as to form a square matrix below, where both trees starts from top-left (as shown), and ...
2
votes
2answers
205 views

Plot tree edges of a tree-form list

I'm trying to plot a tree from a tree-form list. The nodes should be connected from left to right (as usual). My range values are ...
10
votes
7answers
940 views

Extract left-upper triangular data from a square matrix-form list

Hopefully, this question is not too basic or obscure. I'd like an idea on how to extract this {{1}, {5, 2}, {9, 6, 3}, {13, 10, 7, 4}} from ...