# Questions tagged [tree]

A tree is a widely-used data structure that emulates a hierarchical tree-like structure with a set of linked nodes.

13,557
questions

**0**

votes

**1**answer

10 views

### Determine if an array will generate the same BST provided - Use Recursion

I have a problem that I am running into a few issues with, the question is as follows:
Given a pre-constructed Binary Search Tree and an array, determine if the array will produce the same Binary ...

**0**

votes

**0**answers

4 views

### Deserializing JSON into an object with an abstract list and a non-abstract list

I want to deserialize the following JSON into my C# Tree object. The tree structure cannot be edited.
JSON:
{
"Root": {
"Type": 0,
"children": [
{
"Type": 1,
"Name": " ...

**0**

votes

**1**answer

42 views

### Solutions for a Dynamic Infinite Tree Structure in Python

I am trying to build a Tree Structure, starting at a point 1, which can branch into infinte directions. Every point can path into infinite other points ( 1.1, 1.2, 1.3, ... ) and each of those points ...

**2**

votes

**2**answers

43 views

### How transform data from tree of objects to array of objects like this

I want to convert data from an object tree to an array of objects of this kind
I can’t do if you can give me an algorithm or a solution to this problem. Any thought you can grab onto. My brain ...

**0**

votes

**1**answer

28 views

### How to get a difference between two custom trees?

A have the following classes that describe repository of files. There is a server that acts as a main repository and then there are multiple client machines.
class Entry
{
String name;
String ...

**1**

vote

**2**answers

59 views

### Convert JSON to C# complex object

I have this structure in C# and I want to create JSON that can be translated to it successfully so that I can easily find my mistake in the JS logic.
public class Tree
{
public Root Root { ...

**0**

votes

**0**answers

18 views

### warning : syntax ambiguity - badly delimited number '3B' in line 2 of <stdin> splits into two tokens

I am trying to run this python file. The output is coming as such - see the attached screenshot. When I am using this command 'python tree_to_graph.py | dot -Tpng -otree.png' to get the graph, I am ...

**0**

votes

**2**answers

58 views

### What's this tree traversal called?

Given a tree with A at the root
A
+-- B
| +-- C
| +-- D
+-- E
+-- F
+-- G
I want the traversal to be
C,B,A,D,F,E,G
Which could be constructed by starting with all the paths from ...

**0**

votes

**0**answers

19 views

### Issue in implementing filtering for multiple keys of same name

So i want to implement a filter that checks the input and matches logic provided in the filter parameter.
import operator
class InvalidQuery(Exception):
pass
class Filter(object):
...

**0**

votes

**1**answer

32 views

### How to insert elements in a Binary Search Tree, after entering the root element?

I was writing a C-program for Binary Search Tree, with only root as the global variable and used recursion for inserting elements.
struct Node {
int data;
struct Node *left, *right;
} *root =...

**-1**

votes

**2**answers

26 views

### How does this recursive function works, is it about computation structures?

I'm working with a tree traversal code, I have been given the pseudocode, and I implemented it in python, but I still can't figure out how it works
InOrderTraversal(tree):
if tree = nil:
...

**-2**

votes

**0**answers

66 views

### Return list of list of leaves Rose Tree

Want to write a function that takes in a rose tree and returns a list of list of leaves where leaves are grouped if they have the same parent node. For example, an input of:
Rose 6 [Rose 7 [Rose 1 [],...

**1**

vote

**1**answer

11 views

### Question about Find the maximum depth of a tree

maxDepth('1') = max(maxDepth('2'), maxDepth('3')) + 1
= 2 + 1
/ \
/ \
...

**2**

votes

**1**answer

42 views

### How to build a tree sideways and downwards?

How can I build a tree downwards and horizontally?
I current have a tree:
data Tree a = Node a [Tree a]
Then, I have a root Int and list of [Int]
1 and [2,3,4]
I want to build a tree like
...

**0**

votes

**0**answers

72 views

### stuck with minimax algorithm - what next? Haskell

I'm writing a basic MiniMax algorithm for a 2 player board game. So far I have a function that evaluates a board and returns a score. I have a function that returns a rose tree of all possible moves (...

**0**

votes

**0**answers

8 views

### Which Tree traversal String is unique?

Assume we have a tree and we want to serialize it.
Example:
Tree:
1
/ \ ...

**-1**

votes

**1**answer

36 views

### Non-exhaustive patterns in function. Creating rose tree Haskell [duplicate]

I'm trying to write a function that combines a list of rose trees with the their parent node being the highest values of the root nodes of the given rose trees. For example;
RosesToRose [Rose 1 [...

**0**

votes

**0**answers

27 views

### Convert array of words to tree

Im writing my own parser,lexer,interpreter.And i need to make a codeblocks tree,for example i have a text file:
word0
{
word0_0
{
word0_0_0
{
}
}
}
word1
{
word1_0
{
}
...

**-2**

votes

**0**answers

22 views

### Add objects into certain place in a tree [on hold]

I've recently been working on an implementation of a tree type structure in js, link to code below, and I'm wondering how I can perform a specific task with it. It's a bit of a mess and not ...

**-2**

votes

**1**answer

58 views

### Delete an element in a tree in Haskell

data BinaryTree a = Null | Node (BinaryTree a) a (BinaryTree a)
deriving Show
type BsTree a = BinaryTree a
treeDelete :: (Ord a) => (BSTree a) -> a -> (BSTree a)
treeDelete a btree = ...

**0**

votes

**0**answers

24 views

### Finding height of a tree without right and left references

I've been trying to get the height of the root of 2 trees (same root). I just started working with trees and this way of traversing them without left or right references is causing me some difficulty. ...

**1**

vote

**1**answer

39 views

### Given a binary tree, find the horizontal distance between 2 nodes at the same level, also counting the position where the node is not present

Let me be very clear that am not getting what Horizontal distance is.
But still from my point of view. Horizontal distance means : missing or existing nodes between given nodes at the same level.
...

**0**

votes

**3**answers

34 views

### Find depth of node in tree

I am trying to write a function that returns the depth of a node in a non binary tree. I've been trying for the past few hours and getting nowhere so any help would be appreciated. I keep getting 1 as ...

**1**

vote

**1**answer

44 views

### Exception thrown when calling the destructor on postOrderDeletion

The goal of the program is to create an object call Product and add that product object to the tree object. Once you add six or seven products, the main function needs to call the destructor (.~...

**0**

votes

**0**answers

7 views

### how to change each other data in tree

I have one problem.
I create tree structure data from array in javascript.
But when source json array change, tree structure data has been changed same.
I want to not change tree structure data.
How ...

**0**

votes

**1**answer

24 views

### Print parent name for each selection when selected multiple nodes in Tkinter tree

I want user to select multiple nodes from different branches of Tkinter Tree. So that I can do further process I should know the parent branch of each selection.
When I select just one node I am ...

**0**

votes

**1**answer

27 views

### How to build tree structure from flat array

I have an array of menu items:
Array
(
[0] => Joomla\CMS\Menu\MenuItem Object
(
[id] => 101
[menutype] => mainmenu
[title] => Home
...

**0**

votes

**0**answers

30 views

### Updating balance factor in AVL tree after rotation - what am I doing wrong?

I am working on implementing an AVL tree in c++, and am familiar with the concepts of single and double rotation. I have implemented the tree successfully by calculating balance_factor = height(...

**-1**

votes

**0**answers

10 views

### Are there any python libraries which can help build interactive tree diagrams? [on hold]

I have a dataframe that contains attributes like course code, course title, description, semesters offered, pre-reqs etc. My main goal is such that if I click on a course code, it should show all it's ...

**0**

votes

**1**answer

21 views

### Skewed binary tree vs Perfect binary tree - space complexity

Does a skewed binary tree take more space than, say, a perfect binary tree ?
I was solving the question #654 - Maximum Binary Tree on Leetcode, where given an array you gotta make a binary tree such ...

**-1**

votes

**0**answers

30 views

### Function to return height of binary tree,returns one more than actual height

Only the height function is written by me and so I don't have any control over the rest of the code.
I don't know what is wrong.
Please help, thanks in advance
class Node:
def __init__(self, info)...

**-2**

votes

**1**answer

68 views

### Find all the partial paths in a tree

I am trying to create a Haskell function that generates a list containing all the partial paths of a tree, given the tree implementation data Tree a = Empty | Node a (Tree a) (Tree a). For example, if ...

**1**

vote

**0**answers

29 views

### splitting a B-Tree array with while loop

I'm completely new to stack overflow and very new to coding so please forgive me if I make any errors. I need help writing a while loop in Java. The loop is part of a B-tree and we need to demonstrate ...

**0**

votes

**2**answers

34 views

### Creating a binary Tree and search function

I am creating a binary tree and want to just Search function but I want to know how many nodes are visited to find a value. in the search function.
Here is the hearder file
#ifndef INTBINARYTREE_H
...

**-2**

votes

**0**answers

12 views

### how to make a mind map (left and right tree) from a tidy tree in D3

i want to make a left and right tree from tidy tree, is there an easy way to do it? i tried couple things but they didn't work perfectly, like the picture shows i just took the nodes that have the ...

**0**

votes

**1**answer

21 views

### Oracle return tree having all combinations

I need a query that will return all women within the group.
Example data table (Oracle 11g):
with t as (
select 'K' as GROUP_NAME, 1 as ELEMENT_ID from dual
union
select 'K' as GROUP_NAME, 2 ...

**-3**

votes

**0**answers

27 views

### debugging and free tree sort in c ( linux)

SO I just need to add a tree sort, but I have some error when run it, please help me to debug and add free binary function in free_btree(struct BTreeNode **node);
The description is in a picture, to ...

**2**

votes

**2**answers

31 views

### R-tree - Remove algorithm using reinsertion

I am trying to implement an R-tree in scala following the guidelines from the original paper about the R-tree structure. In the deletion algorithm section is stated:
Reinsert all entries of nodes ...

**0**

votes

**1**answer

35 views

### How can I get all child nodes of general tree in Python

My tree has the following structure:
tree={'0':('1','2','3'), '1':('4'), '2':('5','6'), '3':(), '4':('7','8'), '8':('9','10','11')}
How can I wrote Python code to retrieve all given child nodes of a ...

**-5**

votes

**0**answers

36 views

### Debugging and free tree sort in c

Help me to debug my tree sort in C and, also help me to free binary tree
in this function free_btree(struct BTreeNode **node)
I have an error in **array = node -> data
// Tree sort algorithm
//...

**1**

vote

**1**answer

33 views

### Binary Tree Level Order Traversal in Python

so give the following tree:
I should return the level order traversal of the tree from left to right:
so the above example would output a list of lists :
[ [3], [9,20], [15,7] ]
I ...

**0**

votes

**0**answers

35 views

### How to find the immediate parent of every node in any given tree (NOT neccessarily binary tree)?

Presently I am using Breadth First Search traversal to find the parent of every node in the tree, where the array "parent" has the parent information for each node.
I have also tried DFS, both of ...

**0**

votes

**1**answer

34 views

### Compare Two strings in O(logn) with some pre-processing and assumption

I am thinking if it possible to compare two string in O(log n) with some pre-processing and assumption.
My pre-processing is to store the string as the AVL tree where the value of the node is the ...

**1**

vote

**1**answer

48 views

### Adding size to dynamic tree from last column

I need to create a nested dict structure where the number of children can vary at each level.
Appending “size” element to last json child element for a sunburst diagram
Tree creation is covered in ...

**1**

vote

**1**answer

94 views

### Recursive fractal 2d tree drawing in webgl

I'm trying to draw a simple binary fractal tree in webgl, however the branches aren't going in the proper angles I want. I am drawing the tree by plotting the points of the vertices into an array, ...

**0**

votes

**1**answer

39 views

### Node* vs Node in main

I am coding a binary search tree.
class Node {
public:
Node* left;
Node* right;
int data;
Node(int x) : data(x) {}
void insert(int value) {
if (value < data) {
if (left == ...

**0**

votes

**0**answers

24 views

### How can I print number of zig, zigzig and zigzag rotations in a splay tree

I need to print number of zig, zigzig, zigzag rotations in my splay tree having three functions: splay,insert and delete. There seems to be an error in my splay function( in updation of the z,zizi,...

**0**

votes

**0**answers

8 views

### How to get only immediate child nodes in Model Tree Structures with Materialized Paths in MongoDB

I have a mongo DB document structure that follows the pattern of the materialized paths (http://docs.mongodb.com/master/tutorial/model-tree-structures-with-materialized-paths/)
With this design ...

**0**

votes

**2**answers

46 views

### List tree view using eloquent

I have this table structure below
TABLE VIEW
+------+---------------+---------------+---------------+
|id | group_name | sub_group | title |
+------+---------------+---------------+...

**1**

vote

**0**answers

45 views

### Solved: Building a tree from postfix expression C++

I am currently working on calculating the value of a variable postfix expression, eg. a b + b c - *. For a specific state, a=1 b=2 and c=0, I can solve it with using a stack. Due to many possible ...