16,770 questions
2
votes
1
answer
70
views
Laravel deleting event prints wrong children titles in recursive tree delete
I have a self-referencing Laravel model for a category tree. Each node can have children, and I want to delete a node together with all of its descendants.
My relationship looks like this:
public ...
-4
votes
0
answers
38
views
Sorting a flat list to hierarchial nested dict when ONLY when parent is known [duplicate]
This post is followup to Nested dict with parent/child relation,, which was closed due to duplication. However, after 3 days....I will give it a try again.
To problem is following. I am trying to sort ...
2
votes
0
answers
117
views
Why does HashMap in Java still show near O(n) performance under heavy hash collisions despite treeification in Java 8? [duplicate]
I understand that starting from Java 8, HashMap converts buckets with high collision into red-black trees to improve worst-case performance from O(n) to O(log n).
However, when I intentionally create ...
0
votes
1
answer
47
views
Why does JAX broadcast prefix as None values when the full structure contains None, instead of broadcasting prefix values
I'm a bit puzzled by the following jax behavior (version 0.6.2).
Normally, if I broadcast a prefix tree into a structure tree, the value of the prefix is broadcast into the structure:
out_tree = jax....
0
votes
1
answer
89
views
SwiftData added items to a subfolder in a tree are only visible after restart of app
My SwiftData app contains of two main model classes forming a tree, Folder (root and sub) and Entry (leaf), which I show in a List - this all works as expected.
To add new items, I use AddWindow, ...
Advice
0
votes
2
replies
35
views
Applications for a pattern matching on unordered trees with wildcards/variables
For one of my projects, I have been working on a pattern matching engine that determines if a pattern tree can match to a target tree. The trees are rooted, the children are unordered, and the nodes ...
10
votes
1
answer
675
views
Is the brute-force solution for "Is Binary Tree Balanced" really O(n^2) with early exit?
I’m looking at the classic “is binary tree balanced” problem (LeetCode 110 style):
Given a binary tree, determine if it is height-balanced.
A binary tree is height-balanced if for every node, the ...
Advice
0
votes
4
replies
87
views
What is the difference between a AVL and Redblack tree
Explain where to use AVL tree and where to use Redblack ,explain the key concepts in these trees like the time complexity and how to implement it.where these trees are used in real world applications....
0
votes
4
answers
175
views
heap-use-after-free when incorrectly assigning pointers during binary tree inversion [closed]
I was attempting the binary tree inversion question on Leetcode
https://leetcode.com/problems/invert-binary-tree/
I came up with this solution
TreeNode* invertTree(TreeNode* root) {
if (root ==...
0
votes
0
answers
74
views
How do I properly insert 3 into my nested list tree?
I am working on a program that is supposed to build a tree using nested lists in Racket. I believe I am very close, but I am stuck on one section of my insertion testing process.
The syntax for my ...
0
votes
1
answer
112
views
How do I rewrite paths in an AST's import tree?
I'm writing a program that will update a Rust project's imports to be from their new locations after a breaking change in a library. In this instance, I'd like to flatten all imports from vexide::...
6
votes
3
answers
418
views
Find any single 2D point within radius, but fast
I've got a list P of 2-dimensional points, 100 ≤ |P| ≤ 100000, and a list C of circle centers, 100 ≤ |C| ≤ 100000.
All coordinates (x,y) ∈ P or (x,y) ∈ C are integral, 0 ≤ x,y ≤ 4095.
P and C may ...
2
votes
1
answer
126
views
Display game variation tree using compact vertical layout
I want to create a multi-line string that can be printed out or displayed via curses. This string displays the moves and variations of a go/weiqi/baduk game from an sgf file using unicode characters. ...
0
votes
1
answer
70
views
How can I compare a tree with different node types to a list of courses to see which courses have been completed and which haven't?
I'm working on a transcript analyzer personal project and I'm having an issue comparing the courses that are read in from the transcript with the required corses. The required courses are stored in a ...
-2
votes
1
answer
108
views
Treelib does not show hierarchical tree node data [closed]
Using tree package treelib in Python I define a small tree that is slightly modified from the description for command show:
from treelib import Tree
tree = Tree()
tree.create_node("Root", &...
-1
votes
0
answers
56
views
Tree (closure table) does not save children relations to _closure table
I have the following entity:
@Tree('closure-table')
@Entity()
@Unique(['target', 'slug'])
export class SupportNodeEntity extends TreeNodeEntity {
@Column({ type: 'enum', enum: SupportNodeVisibility, ...
0
votes
4
answers
614
views
Answer sum of values on tree path, with updates, efficiently
You are given an unweighted tree with N nodes and each node starts with value 0. There will be Q queries. The 1st type of query will change the value at a node to a new value. The 2nd type of query ...
2
votes
1
answer
210
views
LeetCode 199. Binary Tree Right Side View constant memory complexity
I'm trying to solve LeetCode 199.
Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.
I've ...
3
votes
1
answer
176
views
How to ensure correct destructing of a non-regular tree?
I need a function that parses a string to create a non-regular tree and returns a pointer to its root. In the case of a parsing error, an exception is thrown. My current attempt leaks memory.
How to ...
1
vote
0
answers
75
views
Ant Design Tree keeps scrolling with the mouse pointer even after releasing the mouse (during DnD), and also when the pointer is outside the tree
Description:
I'm using the Ant Design Tree component with drag-and-drop enabled. During drag, the tree auto-scrolls based on the mouse position — which is expected. However, it keeps scrolling even ...
2
votes
2
answers
163
views
How to make a tree support dark/light mode?
All the pages I have been able to add support for dark/light mode. One page has a tree and everything I tried failed and most changes made the formatting (text, alignment, etc.) change, for the worse. ...
0
votes
0
answers
155
views
How to construct an AVL tree from a set of keys: 10, 20, 5, 4, 3, 2, 30, 40?
I'm trying to understand how an AVL tree is built from a sequence of integer keys. The keys I have are:
10, 20, 5, 4, 3, 2, 30, 40
I want to construct the AVL tree step by step and see how rotations ...
2
votes
1
answer
135
views
Get matrix of branch actual length to species tips
Based on this example I have a phylogenetic with species at the tip and branch lengths (that are not necessarily 1). My goal is to calculate phylogenetic diversity multiplying a species community ...
0
votes
1
answer
46
views
Click Events of JSX Elements rendered programatically in the dom not setting state right
This is a weird one but I'm a major novice when it comes to React, I'm probably just doing this completely wrong but I'm trying to dynamically render a content tree. It starts with a single node and ...
-2
votes
1
answer
147
views
Constrained MST: Find a spanning tree of weight ≤ T that minimizes the number of red edges
We are given an undirected graph ( G = (V, E) ), where:
( V ) is the set of vertices (or nodes),
( E ) is the set of edges.
Each edge ( e ∈ E ) has two attributes:
A weight ( w(e) ), which is a ...
2
votes
1
answer
234
views
Phylogenetic Tree with ggtree - Outgroup branch display
I am struggling with a R script I made to visualize a phylogenetic tree obtained after aligning (mafft), curating (bmge) and tree inference using FastTree and a GTR model.
My problem is how the ...
1
vote
1
answer
94
views
How to plot UPGMA phylos with sub selection [closed]
First time working on a network in R, and I was looking into some possible packages/libraries to do so. There is this guide using ggraph that seems pretty complete and has some nice features I'm ...
1
vote
1
answer
148
views
Finding bracketings of an expression
I'm trying to find all possible bracketing of an associative operation.
There's only one possibility for n=2 variables: (a + b)
∘
|
+--------+
| |
a b
For n=3, there are 2 ...
3
votes
1
answer
873
views
Difficulty setting up threaded BST in C++
I'm having trouble implementing a threaded Binary Search Tree in C++. I have a non-threaded tree completely implemented (see below code). What I'm having difficulty with is setting the threads to ...
0
votes
0
answers
33
views
How to correctly implement back references to parent objects in Rust [duplicate]
I have been working on a DOM object in Rust and to insure document integrity I want to implement back references to parent objects, prevent circular references, etc.
Minimally my code looks like this:
...
1
vote
1
answer
62
views
is it posible to fit a multivariate linear model using lmtree?
I want to fit a lmtree where the response is multivariable. You know that you can fit a Multivariate Multiple Regression using lm function as follows:
lm(cbind(Y1, Y2) ~ X1+X2+X3, data = my_df)
so I ...
2
votes
2
answers
183
views
How to add checkboxes column in tree view?
I'm currently creating a custom Odoo13 module where I want to display a wizard to the user with a table of values, so they can select one or many rows and after clicking a button, perform an action ...
1
vote
1
answer
96
views
Generate a random matrix in Python which satisfies a condition
I manually define the following 16 matrices in Python :
matrices = {
"Simulation 1": [
[1, 1, 1, 1, 1, 2],
[1, 1, 1, 1, 2, 2],
[1, 1, 1, 2, 2, 2],
[1, 1, ...
0
votes
0
answers
45
views
Determining order of tree operations when tree state is subject to constraints
I have data modeled as a tree, where the data in each node is a name field. No two sibling nodes may have the same name.
I have copies of the tree representing the state before and after a sequence of ...
0
votes
0
answers
86
views
How to Calculate Time Complexity Using Recurrence Tree for T(n) = T(n - sqrt(n)) + n^2
I'm trying to analyze the time complexity of the following recurrence relation using the recurrence tree method:
T(n) = T(n - sqrt(n)) + n^2
The challenge I'm facing is determining the height of the ...
2
votes
2
answers
287
views
Flatten a hierarchy with recursive LAMBDA formula, or with Power query?
In excel I have this table with 2 columns :
Table called T_DATA
dataset
datasource
APP1
DTM1
DTM1
Dataset1
DTM1
Dataset2
DTM1
Dim1
DTM1
Dim2
Dataset1
Raw1
Dataset2
Dataset3
Dataset2
Raw5
Dataset3
Raw2
...
2
votes
2
answers
261
views
Convert SAS hpsplit output to Python Code / object
I have models that were designed trough SAS hpsplit procedure, outputing results to SAS files.
The content of the SAS files are quite complex... Despite being only in standard 'if then' format, they ...
1
vote
1
answer
153
views
Order Statistic (OS) Trees
In an Order Statistic Tree which is also AVL, if the dimension of the left subtree is 2, what is the maximum dimension of the right subtree?
What I think is that we can add 6 nodes in the right ...
1
vote
1
answer
108
views
Maximum Path Sum Between Red Nodes in a Binary Tree
Problem Statement
I am trying to solve a variation of the Maximum Path Sum in a Binary Tree problem where some nodes in the tree are colored red. The path sum is only valid if:
The path starts and ...
0
votes
1
answer
78
views
Efficient way to flatten account hierarchy so that parents of each child node is displayed in adjacent columns?
This hierarchy has several top level parent nodes which roll down into children nodes which roll down into varying levels of depth containing deeper level children nodes. The level in which a node ...
2
votes
1
answer
235
views
Creating the layout on reactflow canva as a grouped organization chart
I am trying to visualize the organization chart of our company, but there is a part that I have difficulty with and that is grouping. Since Reactflow sells this feature for a fee, I need to develop it ...
2
votes
2
answers
4k
views
NestedTreeControl is deprecated, what should I use in Angular v19 now?
I am upgrading an Angular app to version 19. After the upgrade, I found out that NestedTreeControl is deprecated. Even though it is still available, my IDE shows that
@deprecated Use one of ...
3
votes
1
answer
453
views
Calculate an upper bound on a tree containing sum nodes, choice nodes, and requiring consistent choices
I have a graph containing sum nodes, choice nodes and point nodes. I'd like to maximize the number of points at the root of the graph.
The value you get for a point node is the number of points on ...
0
votes
1
answer
112
views
Handling starred and non-starred nodes in a tree transformation
Problem:
Starred Nodes:
Nodes with names ending in "*" are considered "starred."
Requirement:
Any starred node that is not a direct child of another starred node should become a ...
2
votes
2
answers
52
views
Find a Path to Root in Tree-structured Data (Recursive Function in Python3) [duplicate]
In a class for tree-structured data, I'm trying to get the path from a certain node to the root.
The get_forward_path() method below works in the first run, but its output list grows forever everytime ...
1
vote
2
answers
127
views
How to understand foldTree function?
I have been deeply studying foldTree function in Haskell, which is defined as follows:
foldTree :: (a -> [b] -> b) -> Tree a -> b
foldTree f = go where
go (Node x ts) = f x (map go ts)
...
1
vote
1
answer
87
views
Print Binary Tree
I am trying to visually print out a simple binary tree in Java.
Here is the full code:
class WordPoint {
private final String word;
private final float pointValue;
public ...
0
votes
1
answer
27
views
Select elements between two elements in HTML, at different levels
Alternative headline: traverse all nodes in a tree between two nodes.
I have a DOM tree (an ordered tree, where child elements at each level have a specific order). I am given start and stop nodes in ...
0
votes
1
answer
139
views
solution to factorial problem using dynamic programming resulting in more time than simple recursion
I was just starting out with dynamic programming and tried solving factorial problem using the same, i used binary tree for underlying data structure, but when i thought of comparing it with normal ...
0
votes
1
answer
90
views
How to Calculate the Number of Pairs in a Tree Based on Maximum Edge Weight?
I am working with a weighted tree and need to answer multiple queries efficiently. Each query asks for the number of pairs of vertices (u,v) such that the maximum edge weight on a simple path between ...