Click here to Skip to main content
15,893,161 members
Everything / Trees

Trees

trees

Great Reads

by Dirk Bahle
A list of advanced tips & tricks on Virtualized WPF TreeViews
by Dirk Bahle, Alaa Ben Fatma
Tips & tricks on visting and searching nodes in WPF TreeViews
by Vyacheslav Voronenko
Three approaches to store tree like structures with NoSQL databases in MongoDB
by BrainlessLabs.com
This tip describes a n ary tree structure.

Latest Articles

by IAmJoshChang
How to traverse a postorder binary tree
by Vlad Neculai Vizitiu
Mocking/stubbing lambda expressions to have a bit more control over our unit tests
by Akshay Srinivasan2
This article describes a technique to quickly retrieve and present hierarchical information from a flat relational database table with only one table scan.
by chuck in st paul
This is a utility program for bulk/batch renaming of files that demonstrates using and creating events

All Articles

Sort by Updated

Trees 

20 Sep 2023 by Richard MacCutchan
Using a recursive method means you need to add the result of calling the method to your current value. So if root or root.left are null you return zero. If root.left.left is null, then you return 1, as there is only a single leaf. But if...
20 Sep 2023 by Kusum Verma
Given the root of a binary tree, return the sum of all left leaves. Please give me a detailed dry run as I am not able to find the error in my code. I know the correct answer, but cannot analyse my code. What I have tried: /** * Definition for...
19 Sep 2023 by Patrice T
Quote: I am unable to find error in this code Probably time to learn debugger. Why are you killing the previous value of sum in this line ? sum = left+ right; Your code do not behave the way you expect, or you don't understand why ! There is...
19 Sep 2023 by OriginalGriff
Quote: I know the correct answer but cannot analyse my code. That's a pity, since you wrote it and thus are the best person to fix it as you understand what it is doing! Compiling does not mean your code is right! :laugh: Think of the...
10 Aug 2023 by pavan idirect
I am trying to come up with a design to efficiently send a tree data structure (each node can have more than 2 branches) to a socket/different process etc. There seems to be a cap on how much data can be sent in one message (1500 Bytes). The tree...
27 Mar 2022 by SHEIKH AHNAF AZMAIN
The objective is to make a linked-list tree of groups of students of a subject. the tree should work with the subject being the root, the group leaders being the first level of leaves, and the members of the group branching from their respective...
27 Mar 2022 by CPallini
I think you should revise your data structure. I propose you a skeleton (you might complete it adding dynamic memory allocation and all the details) #include #include #include #define SIZE 100 struct MemberNode {...
14 Mar 2022 by Member 15561967
I have a tree structure in my program. I need to find special combinations of vertices that will be added to two lists. Those lists just need to store labels of those vertices. Rules for List L1: 1. If a vertex has two children and one of those...
14 Mar 2022 by OriginalGriff
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for...
16 Jan 2022 by Sourabh Chavan
I am a beginner in java and learning Data Structures and algorithms and I am currently learning trees. However, I cannot understand how a tree has been implemented using ArrayLists. I cannot understand the meaning of: ArrayList...
16 Jan 2022 by Luc Pattyn
(1) ArrayList children; declares an object called "children" with type "ArrayList" where ArrayList is a particular collection of objects, in this case all those objects must be instances of type TreeNode. So children will be a bunch...
12 Dec 2021 by Member 15099277
I want to display the inorder, preorder, and postorder and also the value of the given expression Now inorder,postorder and preorder display successfully but value of give expression is not display and still give me error. it give me error on...
5 Sep 2021 by Priyanka Somani
I'm trying to understand the low time used in tarjan algorithm using the second example given on GFG Tarjan's Algorithm to find Strongly Connected Components - GeeksforGeeks[^] What I have tried: According to GFG the definition of lowtime is...
24 Apr 2021 by Petr Osipov
Hi all, at an interview I was told B-trees are not binary trees as they are intentionally wide structures containing many children elements that are linked to facilitate reversed order traversals is the second part talking about linked...
20 Jan 2021 by Emre Yaşar
Draw an expression tree for " k p * t / m n r - $ + ." What does ıt mean " $ " symbol . in Data Structure . What I have tried: $ ı dont know that symbol meanıng So ı cant tried anything.
20 Jan 2021 by Patrice T
Quote: What does ıt mean " $ " symbol . Do you really need to know ? The '$' look like an operator in this expression, the only mystery is unary or binary. By the way, I don't know either whet is the '.', since it is not a multiplication. You...
20 Jan 2021 by OriginalGriff
C has no operator "$" - so you will have to go back to your teacher and ask him exactly what it means in this context. SInce expression trees rely on operator precedence you need to know where each operator "fits" in the scheme of things before...
3 Jan 2021 by muhammad mushtaq2
write a function treeType(Node *) in c++ When root node of a data structure is passed it checks following things •Is it a Tree? •Is it a Binary Tree? •Is it a BST? What I have tried: #include #include using namespace std;...
3 Jan 2021 by OriginalGriff
We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us...
8 Aug 2020 by Vlad Neculai Vizitiu
Mocking/stubbing lambda expressions to have a bit more control over our unit tests
21 May 2020 by Akshay Srinivasan2
This article describes a technique to quickly retrieve and present hierarchical information from a flat relational database table with only one table scan.
9 Jan 2020 by Maciej Los
For MS SQL Server, please read this: Hierarchies WITH Common Table Expressions | Microsoft Docs[^]
9 Jan 2020 by Member 14221689
I have SQL table for Binary tree. Id | Name | Parent_ID | i want to calculate 5 levels of complete binary tree for parameter node which is passed to stored procedure. What I have tried: Recursive function Using while loop
3 Sep 2019 by Insoft Nepal
For the first time jstree is loaded but if i callback jstree through js ,then it is not loaded. What I have tried: var PGroupdata = JSON.parse(newStr) $('#data').jstree({ 'core': { 'data': PGroupdata } }); ...
3 Sep 2019 by jimmson
I would say that your jsTree script is loaded after your code. Try to initialize it on the page load: $(function () { $('#data').jstree({ 'core': { 'data': PGroupdata } }); }
25 Aug 2019 by RickZeeland
Here is a tutorial: Binary trees - Learn C - Free Interactive C Tutorial[^] And here is a nice explanation: binary-search-trees-explained-5a2eeb1a9e8b[^]
25 Aug 2019 by higii
Trying to learn about Binary Tree while preparing for an exam, and I came across this code. And even tho it looks like it makes sense I simply cannot understand the purpose of this and how it actually works, so can anyone please elaborate? And this is the code : space += 5; ...
5 Aug 2019 by geek code
I came across this problem while giving a sample test. The problem was that we have given a tree which is undirected. We can start from any node of our choice. Initially we have power "P" and while going from one node to other node we loose some power "X" (consider as cost of travelling) and...
19 Apr 2019 by Simon_Whale
I think this would be a good read on how to store AVL trees in SQL Server. Binary Trees in SQL - Simple Talk[^]
19 Apr 2019 by User 9414576
Greetings ,For my application I need to make AVL trees for tags that would be balanced with every query. What would be a good a database to store this form of data. XML is taking way too much time to store and parse?It is a .NET based project and any help would be appreciated.
12 Mar 2019 by Member 10743491
I am trying to perform insertion in one function and then balance the tree if required in another.Here is my code...node* create_bst(node* tree,node* curr){ if (tree==NULL) { return curr; } if(tree!=curr) { if(tree->key>=curr->key) ...
24 Feb 2019 by chuck in st paul
This is a utility program for bulk/batch renaming of files that demonstrates using and creating events
17 Dec 2018 by dhaya sagar
I need code to read data from text file and display the data in Tree Control...With a condition if, the text in the file not preceded by tab, it should be in parent node and if preceded by tab, it should be in child node. Example: Notepad contains two lines..... Hello -> (not preceded by tab...
17 Dec 2018 by Richard MacCutchan
See CFile Class | Microsoft Docs[^] and CTreeView Class | Microsoft Docs[^].
17 Dec 2018 by OriginalGriff
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action. Try it yourself, you may find it is...
15 Dec 2018 by wprintf
How to encode binary trees for algorithms such as RandomForest
16 Aug 2018 by Gerry Schmitz
Python implementation of Dijkstra's Algorithm · GitHub[^] Implementing Djikstra’s Shortest Path Algorithm with Python – Ben Alex Keen[^]
16 Aug 2018 by Stephane123wer
I am attempting to build a program where a user is able to select a starting and ending point on a map, and the shortest path between those two points is displayed. My code should work for all maps inputted, not just one. I already have placed all the nodes on the map. I would like to connect...
12 Jul 2018 by natuan8687
Solution Please note that my sample code is using ASP.NET Core tag helper of jQWidgets. But it totally works on native Javascript/jQuery. 1. View (Index.cshtml) @model IEnumerable
12 Jul 2018 by Ali Majed HA
HelloI have a table in SQL Data Base named "Groups". with fields :Id Title ParentId the values are shown in jqxTree correctly, but I need to when user clicks on a Product to Update it, jqxTree select the current node for the Group of that product so the user can change it or...
8 Jun 2018 by Patrice T
Quote: Does this code to insert to a tree not work for empty trees? First: read the code and particularly comments. // base case--we have reached an empty tree and need to insert our new // node here second: there is an easy way to know the answer, make a testing program that call the routine...
8 Jun 2018 by BerthaDusStuf
I am reading jumping into c++ and in it there is this code that is made to insert into a tree: node* insert (node *p_tree, int key) { // base case--we have reached an empty tree and need to insert our new // node here if ( p_tree == NULL ) { node* p_new_tree = new node; p_new_tree->p_left =...
17 May 2018 by KarstenK
Your code must fill the rchild and lchild data with another tree. //allocate some tree struct treenode *lnode = malloc(sizeof(struct treenode)); //fill lnode with some data lnode->data = .... (*pp)->lchildstruct = lnode; Best is to write some time-saving functions like struct treenode...
17 May 2018 by Member 13832192
Hello! I have the following C program that adds Nodes to a tree and then the user can select a sorting method. How can I modify the program in a manner that will allow me to add a LChild and RChild to every node? Any help is highly appreciated since I am completely new to BSTs. What I have...
28 Apr 2018 by Patrice T
A B-tree is a structure, basically, a node that contain a value and 2 pointers to 2 child nodes. The trick is that each child tree is a B-tree itself. in this B-tree 1 2 3 4 5 6 7 1 2 3 is a B-tree by itself with just an indentation. A B-tree can have an unlimited depth, so...
28 Apr 2018 by Member 13616463
int k = 200 ; // defined in same class as the function print . public void print ( BNode n ) { for ( int k = temp ; k>=0 ; k=k-30 ) { System.out.print(" "); } for ( int i = 0 ; i
24 Mar 2018 by Pushkar Prabhu
query.OrderBy(col1).ThenBy(col2).ThenBy(col3).ThenBy(col4);
24 Mar 2018 by Srinivasan Hariharan
I have a List object. I am converting this to IQueryable by calling a method AsQueryable().I need to do sorting on multiple columns say for ex. four columns say col1, col2 col3 & col4 using the expressing tree only. Any one has ideas, how to do that.thanksAny help...
19 Mar 2018 by jcsanchez1
I am trying to create a b* tree data structure using list. List> List> I am not pretty sure, in the first one I just get 2 levels of the tree, but in the case, the tree will be deeper? I think in the second case fit more with my needs because I can use a list as an...
24 Feb 2018 by BillWoodruff
Knowing your tree's item nodes are always leaf nodes of a specific type makes your task a bit simpler. I'm going to post a sketch of a structure that will implement a tree of this type which I know works. I say "sketch" because my goal is to assist you in developing your programming skills ......
24 Feb 2018 by Dntdothis
I ran to an issue, I have a task with categories and items, I need to make a menu tree list, it can be N deep, parent can have many children as he wants: Menu tree looks like this: - Category (6) - Category (3) - Item (€0.50) - Category (2) - Item (€1.10) -...
22 Dec 2017 by Dirk Bahle
Tips & Tricks on loading and saving WPF Tree View based content.
8 Dec 2017 by Dirk Bahle, Alaa Ben Fatma
Tips & tricks on visting and searching nodes in WPF TreeViews
22 Sep 2017 by Dirk Bahle
A list of advanced tips & tricks on Virtualized WPF TreeViews
16 Sep 2017 by Dirk Bahle
A list of advanced tips & tricks on WPF TreeViews
24 Jun 2017 by Member 13265840
I am new to Jtree and Java. So, I have a tree structure like this : -Abcd --Efghi ---Pqrst ---Uvwxyz ---Xyza ---Hdwik ---Lmnop ---Bcdef --Tqrsp ---Jumak ----Uoaha ----Lobte -----Cshnt ----Karke Now i want to get the count of Abcd = 14 (i.e Count of all children...
23 Jun 2017 by Patrice T
ppolymorphe wrote: I wouldn't use a tree for this problem, it just complicate things. Quote: Then what should i do, can you help me That is a matter of "problem analyze" : you can build a tree, but do you need to ? As you have already found, you need to read lines 1 by 1 while...
8 Jun 2017 by Member 13248256
Hello all! I am trying to figure out a way to search a BST for its balanced subtree with max height. What I have tried: I have so far been able to find methods to check the height of a tree and to check whether the tree is balanced. I'm having a hard time getting these to work to locate the...
8 Jun 2017 by KarstenK
To get the maximum height you need to store your actual maximum somewhere and compare it with the actual value. And your are missing some edge cases like the last else in MaxBalanced which is missing. You need a fallback in non-balanced trees.
29 Apr 2017 by Member 13161564
I have a Binary Search Tree, some functions in it, not planning to use any other libraries, nor use vectors, I have to use arrays and a tree. This code will mostly work, except for a bug, that for some roots, the functions that add arrays wont work or the printing functions wont work. Basically...
29 Apr 2017 by Patrice T
Quote: No errors, compiles fine. "Compiles fine" means that your code is correct C++, it does not mean that it does what it should as "no error" would mean. "The cat is flying high in the sky.' is correct English grammar, but it is non sense. Quote: Tried debugging, but I'm a novice and it got...
29 Apr 2017 by OriginalGriff
Development is not a case of "write it, compile it, fix compiler errors, compile it, ship it" - just compiling does not mean your code is right! :laugh: Think of the development process as writing an email: compiling successfully means that you wrote the email in the right language - English,...
23 Mar 2017 by Member 13037163
So I have been around the net trying to grasp the concept of recursion, and just when I thought i had understood it.I am not quiet able to understand how the piece of code below works. It is used to show all the elements in a binary tree (Infix order).Can someone please break it down and...
23 Mar 2017 by Patrice T
Quote:Can someone please break it down and explain each step.No, use the debugger to see what the program is doing, you will learn much more and faster.When you don't understand what your code is doing or why it does what it does, the answer is debugger.Use the debugger to see what your...
12 Dec 2016 by Patrice T
As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.When you just ask for the solution, it is like trying to learn to drive...
12 Dec 2016 by Member 12898887
Hi, I'd like to print a given binary tree horizontally in C WITH LINKS between nodes.I've done it without links , when i tried to do it with links it really got messed up... So if anyone can give me the solution that will be very helpful.Thanx...PS: More explanations in the images...
2 Dec 2016 by Member 12884199
You have to find average depth at once .I use this formula->AD(n)=ln(n+1)÷ln2This you can find from the formula as we can find maximum no.of nodes by //n=(2^d)-1Where d is depth of the tree.
1 Dec 2016 by Yateesh KR
I have a custom treectrl class and i want insert some items into tree,is there any possible way to insert items in a sorted order(last created file should display first). Basicaly the treectrl which i have created is used as listctrl so each item is automatically become parent and no parent has...
1 Dec 2016 by KarstenK
For that you must cleary separate the visual display (View) and the data source (Model). Your data sounds more than a ordered list or an array. Insert the data ordered and than reload the data.The list control has a lot of possibilities, so take a look at the articel Using the List...
6 Nov 2016 by Kornfeld Eliyahu Peter
According to the documentation[^] it should be$('#jqxTree').jqxTree('selectItem', element);where element is the LI tag...
27 Jul 2016 by Richard MacCutchan
tree *root = NULL; // Create new root from the class tree of the header fileroot = root.Insert(root, 9); // New node with the number 9 on itThe first statement creates a pointer and sets it to NULL, so it does not point to anything. You then try and call the Insert method on a NULL...
27 Jul 2016 by Bit87
Hello, I need some help with this, I'm trying to call a function from my header file to my main, this function return a structure.The problem here is that I don't get how to call a function that returns a structure from it, I have tried some things but nothing has worked. Output...
16 Jun 2016 by _eol_
This article presents the minimal code necessary to display a hierarchical tree using Popups.
10 Jun 2016 by dipesh deb
I have two folders path. One is fixed - suppose "D:\Test". And another is variable, it may be under "D:\Test" tree (e.g,"D:\Test\abc\xyz" etc.) or in any other place of the local / network places. If the variable folder is under the fixed folder tree, message box - "Found in the folder" ...
31 May 2016 by Hamid Mosalla
Dynamically building JSON tree for use In JavaScript components using C#
20 May 2016 by Qwertie
The A-list is an all-purpose list, a data structure that can support most standard list operation in O(log n) time and does lots of other stuff, too
5 May 2016 by Patrice T
Quote:i've tried everything that i could think of including debugging but i didnt get much insight At least, using the debugger, you should be able to see if find returns something and what, if it fails, you will see why too.It is complicated to say something else without the data.
5 May 2016 by corupted
i have a binary search tree that stores details of countries financial situation,i have added all the countries now i just want to search them by countrynamei have a find method in my BST class that is supposed to do that but it doesnt work, it doesent print anything when i call...
5 May 2016 by Sergey Alexandrovich Kryukov
First of all, you should prefer non-recursive solutions in such cases. A tree can have any depth, so, theoretically speaking, you can face stack overflow (and even practically, for big data sets). Also, recursion may compromise your performance. Trees are perfectly searched...
29 Apr 2016 by Peter Leow
Before crossing over, check their return types. If the return types are not comparable, pick another chromosome. You should have a large population to pick from.
29 Apr 2016 by Sicppy
So in general when you perform a crossover in GA, you directly flip a random section in the "genome", with the corresponding section in the other parent, and mutate it based on the mutation rate.Consider the sequences below:0100 1000 0001 10110010 0110 1101 1111A crossover without...
17 Apr 2016 by leon de boer
You need a dead zone on your Animation transitions make them > 0.1f NOT > 0f you are getting jitter. Hold focus on the character in the object inspector and watch the animator editor transitions.This is the patch to your code but this is not the proper fix which I will explain next if...
17 Apr 2016 by wasicool2
I followed this tutorial on youtube: Unity3D. Top-down 8 directions movement - YouTube[^]. It took me a while but I've almost converted from movement by arrows to mouse touch . but now I have this problem, there's flickering that occurs when the character stops moving. I looked at the link he...
13 Apr 2016 by Gun Gun Febrianza
i wonder how and what is the best method to create a data tree from particular string with specific pattern into TreeView Control in c#?For example i have input string like this :(program (statements (statement (var_declaration (primitive_type string) (identifier a) = (expression "hi")...
13 Apr 2016 by BillWoodruff
As Sergey suggested, the "big win" here would be to get whatever is producing your data formatted as string into JSON, or XML format; parsing those formats to a Tree data structure, or creating a populated TreeView Control using those formats, is straightforward.If you are going to try and...
13 Apr 2016 by OriginalGriff
This example uses "(" and ")" - but that's a trivial change: c# - Tree structure as string - how to match nested braces? - Stack Overflow[^]
25 Jan 2016 by GravityPhazer
This article demonstrates how you can simply enumerate any generic tree depth-first as well as breadth-first using the described construct. Trees can be serialized binary (using the BinaryFormatter), custom binary and as XML.
3 Jan 2016 by Sachin Makwana
I am working on a project in which i need to consolidate 2 or more decision tree generated by J48 algorithm.full scenario is as follows:- My work is in distributed data mining.- Students educational record is being used for evolution purpose.- there are 4 server and 4...
28 Dec 2015 by Khaleel Mahalthy
CmdString = "query"; cmd = new SqlCommand(CmdString, con); sda = new SqlDataAdapter(cmd); dt = new DataTable(); // Levelid,levelname is retrieved in the DataTable 'dt' sda.Fill(dt); for (int i = 0; i
23 Dec 2015 by manoj1412012
we are loading the xml file path from a textbox as shown below Session["CurrentXMLFile"] = txtFilePath.Text; LoadXMLTree(txtFilePath.Text);binding the xml file to tree view as shown belowprivate void LoadXMLTree(string fileName){ try { ...
16 Nov 2015 by girish sp
I have to work with c tree(Conditional Inference Trees) in my Asp.net project,i know c tree is directly not supported, so i am looking for the alternatives which i can start with, i came across r.net i cannot use it as it requires executable to be installed on client side, i went through the...
11 Nov 2015 by Yuriy Magurdumov
Simple generic data structure to maintain hierarchical objects
24 Sep 2015 by Milan Matějka
Representing Lambda Expressions as delegates and expression trees.
25 Aug 2015 by XyedBilal
Turn horizontal d3 tree to vertical
11 Aug 2015 by Christian Specht
Building a pseudo-dynamic tree menu with Jekyll
3 Jun 2015 by Mahesh Sonvane
I am working on tree formatting of an associative array:Array( [8] => Array ( [name] => David Clance [email_id] => dclance@gmail.com [designation] => Chief Executive Officer [member] => Array ( ...
14 May 2015 by Andy Lanng
Here is a threaded version of your code: private void AddNode(XmlNode inXmlNode, TreeNode inTreeNode) { //XmlNode xNode ; TreeNode tNode ; XmlNodeList nodeList ; int i = 0; if (inXmlNode.HasChildNodes) ...
14 May 2015 by dinesh_redhawk
Hello Friends,I need to display a large XML file (>21MB) in a tree view control in a C# Windows Form application. I have written the code which is working for small XML files but when i am trying to open a BIG XML file (>1 MB), its taking too much of time.Can anyone suggest how i can...
4 May 2015 by Tomasz_Wisniewski
A treap implementation in C