Questions tagged [tree]
A tree is a widely-used data structure that emulates a hierarchical tree-like structure with a set of linked nodes.
16,015
questions
0
votes
1
answer
16
views
Binary Search Tree insertion Code UNEXPECTED behavior
I am inserting a node to the Binary Search Tree and I encountered an unexpected behaviour.
My question is - Why last line in insert function is optional ?
The last line takes care of the recursive ...
0
votes
0
answers
16
views
Convert General "Family" Tree to Binary Tree (Not BST)
I am currently considering different ways to accomplish the task of converting a family-type general tree (where each parent can have as many children as necessary) to a binary tree such that the left ...
2
votes
2
answers
34
views
Let X,Y,Z,W be words with vector frequency $(x,y,z,w)$ , Find an optimal code
Let X,Y,Z,W be words with vector frequency (x,y,z,w) such that .
Find certain requirements about x,y,z,w such that W=00,Z=01,Y=10,X=11 is an optimal code.
My solution :
Using Huffman coding, I think ...
0
votes
0
answers
23
views
How do I clean up this R decision tree specifically get rid of all the values under each node
R output is portraying with all values under the nodes, help me clean this up
click here [1]: https://i.stack.imgur.com/LUxFf.png
I cannot add the data, however here is the code, I am new at this ...
-1
votes
0
answers
25
views
Maximum diameter of a tree by removing an edge and adding an edge in any position
I have been trying to solve this question. The only knowledge I have related to this is that I can find the diameter of a tree using 2 dfs calls: First from the root to find the first end-point of the ...
0
votes
0
answers
11
views
How to creat a parent-child hierarchy table by giving the level value in Python (Jupyter)
How can I sort the table into a parent-children format or create a tree using Python (Jupyter)
Currently, I have a CSV with each row of a variable's name labeled level 1 to 6. 1 means it's the first ...
0
votes
1
answer
28
views
Is there a efficient way to find only the combinations of interest from V exciting in P
Is there a efficient way to find only the combinations of interest from V exciting in P
I have a list of something like this.
V = [2,3,5,7,9,12]
Size of V can be anywhere from 0 to 50 based on my ...
0
votes
0
answers
19
views
Searching for a string in a bst fails
if i found the string i just return it if not found I returns 3 suggestions
as 1-the last node before declaring that the node is not found
2-the inorder successsor
3- the inorder predecessor
#...
0
votes
1
answer
14
views
Change binary tree's elements with a given array while protecting tree structure
In java, I have a binary tree. And I want to change it's elements from elements in a given array. But I must protect the structure. After that, I should convert it to binary search tree.
How can I ...
0
votes
0
answers
8
views
Isolation trees - detection anomalies for one variable according to others
I just discovered isolation trees (currently on isotree with R).
I have a time series of meteorological and vegetation physiological responses (every 30 minutes), and I try to detect "...
0
votes
3
answers
45
views
Printing all the paths in a tree from root to each leaf
I am trying to print all the paths from root to leaf in a tree, but having some issues collecting the path items.
Consider the following graph:
In my case though, the result is as follows:
10 -> 8 ...
0
votes
0
answers
18
views
dom tree to abstract syntax tree in javascript [closed]
const domTree = ['div', { class: 'container' }, [
['div', { class: 'row' }, [
['div', { class: 'col' }, [
['img', { src: 'path/to/file.png', alt: 'picture' }],
['br'...
-1
votes
2
answers
40
views
How to loop a tree array with unknown depth and get array blocks?
I found this solution to loop and print an unknown depth array:
printAllValues($arr);
function printAllValues($arr) {
if(!is_array($arr)) {
echo ($arr);
return;...
0
votes
0
answers
7
views
Plot tree with probability of event in each node of RandomForestClassifier estimators
I am trying to plot estimators of a random forest classifier. While the plot is getting created, I am not getting the probabilities of event (binary event in this case flagged as 1 and 0) in the ...
-2
votes
0
answers
14
views
Write the algorithm to find DFS traversal of given tree using stack
Write the algorithm to find DFS traversal of given tree using stack.
Evaluate the time complexity of DFS algorithm
0
votes
1
answer
20
views
Maximum depth of trees
When finding the maximum depth of an N-arr tree, the approach differs slightly from that of a binary tree.
Binary tree max depth:
class Solution:
def maxDepth(self, root: Optional[TreeNode]) -> ...
0
votes
1
answer
20
views
Graph - Algorithm to position nodes
I am trying to create a dynamic graph where users can add new nodes using ELK.js
The graph is a tree that has one root node. I am trying to set the position of nodes in a row using (x,y) position (y ...
0
votes
0
answers
31
views
Creating a tree from edges and nodes dataframes
I am trying to reconstruct the lineage of cells dividing in the microscope and I was thinking of making a tree to visualise it (in R!).
I have a dataframe with the edges that looks like this (Time ...
1
vote
0
answers
41
views
Bounding volume hierarchy traversal in GLSL
I am currently working on getting models to work efficiently in a ray tracer implemented as an OpenGL compute shader. I already figured out how to construct the BVH and have implemented this on the ...
0
votes
1
answer
25
views
child node repeated as parent node in tree on ADF
I have created a tree in ADF from a single recursive view object, but the problem is that the same node is repeated in the parent node and child node like the image bellow:
enter image description ...
1
vote
1
answer
25
views
How does parameters of a method get stored in stack during a recursive call?
I was doing a leetcode question https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-ii/ and I am confused on how parameters for a method get stored during a recursive call.
If a node ...
0
votes
0
answers
25
views
In MySQL, how can I create a recursive query for a non-binary tree structure?
Good morning,
I have two tables according the following scheme
taxonomy
id
parent_id
1
NULL
2
NULL
3
1
4
1
5
4
6
5
translation
language_code
taxonomy_id
field_name
value
it
1
"name"...
1
vote
1
answer
88
views
Creating a tree from list of nodes to represent a pipe network
I working on a simple water pipeline path modeling and listing each path.
In my model, water flows in a single direction always; from root to leaves. No loops.
I would like to create a table of nodes ...
0
votes
1
answer
23
views
Try to build a Breadth First Search algorithm for normal tree in C
I try to build a Breadth First Search algorithm for normal tree, which one node can have multiple(could more than two) children.
The main idea of my algorithm is that I go through all the first-kid, ...
1
vote
3
answers
108
views
Recursive approach for building a tree like object hierarchy does not work as expected
I'm trying to write functionality something like this:
Input:
['A', '-B1', '--B2', '-C1', 'D']
Output:
{'A': {'B1': {'B2': {}}, 'C1': {}}, 'D': {}}
As you can see that B1 and C1 are children of A ...
0
votes
0
answers
28
views
How to get all root to leaf paths in a tree or a graph from a flat structure?
I working on a simple water pipeline path modelling and listing each path.
The model is simple because the pipes do not create loops or grids. It consists of nodes which are representing the edge of ...
1
vote
1
answer
29
views
tailrec implementation of tree depth algo
Please advice is there a way to have a tailrec implementation of "classical" tree depth algo.
import scala.annotation.tailrec
object Tree extends App {
sealed trait Tree[+A]
case ...
0
votes
0
answers
15
views
Is there a way to assign probabilities in a R classification tree?
I have the following code which I'm trying to analyze with a classification tree. Currently it yields the following:
This is not very helpful because all the leaves indicate "No". So now I ...
0
votes
0
answers
37
views
how to print path of a file pointed by a symbolic link in C like tree or ls -l does
here's my problem:
Im writing a simplified tree command with C language.
When I find a file that's a symbolic link i would print something like:
SymbolicFile -> ../.././something..
So i've tried to ...
0
votes
2
answers
45
views
Lua tree construction parser
I have string like this: something $asd:$test$,2$
I need to parse text in $ like a tree structure and start from children.
So, $test$ is parsed first and will be replaced by some function output. Let'...
0
votes
0
answers
30
views
Tree structure in minimax (python)
I am trying to make AI for board game with minimax algorithm, but I have problem with creating a tree structure. I know that you actually don't need to build tree for minimax but I have to. I want to ...
1
vote
0
answers
44
views
How to properly plot a tree (27k nodes) using a circular tree / leave layout
I have this (unbalanced) tree with 27k+ nodes. It is an hierachy. Now I would to plot it as such to obtain a plot something like this (no idea how you would describe it, but I would call it a circular ...
-2
votes
1
answer
46
views
there are some issues in this family tree I made
I have this good family tree but the problem is that the page is funcy like everything is on top of each other how can I fix it (it's better to try it in a coding app because CSS doesn't work here (if ...
1
vote
0
answers
25
views
Binary tree not clearing with each loop iteration
I am using a binary tree to convert prefix expression into infix, and then solving them.
That part works fully.
My issue is the input loop I set up is adding on the new expression to the old tree, ...
-2
votes
0
answers
83
views
construct a binary tree from string in haskell
how do I construct from string representation of binary tree a binary tree ?
I already wrote a function that takes a string representation and converts it to a list of all the characters (so if I have ...
0
votes
1
answer
23
views
ANTLR function to retrieve text from a single node in a parse tree
I want to retrieve text from a parse tree's node but when i use getText(), it retrieves all the text from that node's children.
I have searched but i don't find any ANTLR function that can retrieve ...
0
votes
2
answers
28
views
merging 2 binary trees- Easy
I am trying to merge 2 binary trees, without worrying about making the resultant tree balanced. Here is my solution which does not work. Why are the Treenode ans and head set to 0 when they come back ...
0
votes
0
answers
34
views
Directed SPT vs SPT?
Question:
If a graph contains no negative-weight cycles, does there exist an ordering of edges such that Bellman-Ford computes shortest paths by relaxing each edge at most once?
Answer:
Yes, if there ...
0
votes
0
answers
33
views
Choosing an appropriate data structure for point-intersection detecting
I have some kind of shapes (rectangles, triangles, circles, etc.) that are given by points in space (coordinates). For example, for a rectangle - [0,0] and [5,5] - opposite corners.
There will be a ...
0
votes
1
answer
35
views
Time Complexity of traversing n-ary tree seems to have multiple correct answers, which is most correct?
Ignoring space complexity, assuming each node in the tree is touched exactly once and considering DFS and BFS traversal time equivalent, what is the time complexity of traversing an n-ary tree?
Given ...
-1
votes
0
answers
48
views
Range sum of Binary Search Tree using recursion c++
Hi I'm trying to write a recursive function
int rangeSumBST(node* root, int low, int high){
}
that takes low key and high key and find sum of all values within the two keys (inclusive) without having ...
0
votes
1
answer
19
views
How do get the correct encoded data with huffman tree?
I am trying to encode letters using a Huffman tree.
I already have my tree, I am now given a string of characters and I am trying to encode it using the tree.
I don't want/cannot use dict().
I am ...
0
votes
3
answers
39
views
variables in recursion get reset. Can someone explain how?
I am trying to solve this question from Leetcode
https://leetcode.com/problems/count-good-nodes-in-binary-tree/
This is my solution:
I am not able to understand why is this recursion the count value ...
0
votes
1
answer
21
views
Filtering a complex JSON tree with Deepdash not working
const dataTree = [
{
"name":"PARENT",
"attributes":{
"id":"6989a7d9-5150-49af-8b01-8829035ef83d",
...
0
votes
0
answers
32
views
Rewriting C++ programs to Python tree isomorphism
I saw a program written in C++ to determine whether a tree (not necessarily a binary tree) is isomorphic or not. I think this program is great. I'd like to rewrite it as a Python program. And I did so....
2
votes
1
answer
25
views
DFS and depth tree
I need to decide whether the following statement is true or false. If true, explain why, if false give a counterexample.
Let T be the depth-tree resulting from running the DFS algorithm on a graph G ...
2
votes
0
answers
17
views
Using "mae" and "mape" metric in selecting the best regression tree in R
I'm trying to select the best regression tree using the "mae" or the "mape" metrics, but doesn't seem to recognize it.
My try:
best_complexity <- select_best(tune_res, metric = &...
0
votes
2
answers
34
views
Most Recently Used Index - DS&A / Interview Question
Recently got the following question on an interview with FAANG. Could not understand for the life of me the optimal solution that the interviewer described, and after struggling with it for awhile, I'...
0
votes
0
answers
18
views
How looks like an Expression-Tree (when function calls are involved)
I've found many places that shows expression-trees that involve operators (+,-,*, &&, ||, etc). Here is a simple example:
But I can not find an example when functions (with zero or more ...
0
votes
0
answers
7
views
Can you specify an additive model where the predictors transformations are not necessarily splines but could be trees or anything?
I am trying to create a model of the form
where f1 could be a tree and f2 could be a Gaussian process regressor. Is it possible? What are some sources I could look at?
I do not want to use a stacking ...