A tree is a graph in which there is exactly one path between any two nodes. It is often used as a hierarchical data structure.

learn more… | top users | synonyms

4
votes
3answers
65 views

Tree structure with support for inorder and preorder traversal

I am learning Tree Data Structures and came up with this code for implementing basic Tree Node using class and performing various Tree based operations like Traversals and others. The code works ...
2
votes
1answer
45 views

Mathematical expression evaluator and equation solver

I'm trying to implement a mathematical expression evaluator and equation solver, and based on extensive online research and my own experimentation have come to the conclusion that the best way of ...
3
votes
3answers
237 views

Convert an array to a binary tree

I wrote this code in C++ to convert an array to a binary tree. For instance, int nums[] = {7,5,9,1,7,3} to a binary tree (root-7, root's left child-5, root's right ...
3
votes
2answers
47 views

Searching for nodes in a huge tree

This is supposed to search for a node in a huge Treeview. The node could be found in many places. In other words there may be many nodes and the resulting tree should be expanded depending on where ...
2
votes
2answers
132 views

PrettyPrint a Binary Tree (Follow Up)

I have improved the Pretty Printing of binary tree that I implemented previously. In this follow up I have made changes such that every tree is printed (not just a Complete binary tree). Here is my ...
3
votes
3answers
168 views

PrettyPrint a Binary Tree

I was going through this tutorial for Pretty Printing a binary search tree and decided to implement my own version. Here is my implementation. This version works only for trees that are complete ...
5
votes
4answers
363 views

Recursive Java Red-Black Tree

I've made an attempt at a recursive Red-Black tree in Java. I realise that some of my code could be condensed but I tried to favour readability with this code as Red-Black trees can be somewhat ...
0
votes
1answer
46 views

Least common ancestor in a binary tree

I saw this implementation of Least common ancestor and thought that it was very inefficient as it used Queues. I have tried to implement it using a normal tree ...
1
vote
2answers
70 views

Generic Tree in Java

My implementation of generic Tree structure: ...
3
votes
1answer
42 views

Least common ancestor (LCA) in a binary tree

Find the LCA in binary tree, where a node is also its own ancestor. This question is attributed to GeeksForGeeks. I'm looking for code review, optimizations and best practices. ...
4
votes
2answers
66 views

“Functionalizing” this tree walking method and cleaning it up

I have a MessageTree class that represents a binary tree of negative/positive. I'm looking to improve my walkTree method and ...
6
votes
4answers
448 views

Recursive binary search tree - follow-up

This is a follow-up to Recursive binary search tree changes: Used raw pointers rather than std::unique_ptr const correctness Made variable names more beautiful implemented at() How can I improve ...
4
votes
3answers
378 views

Preorder, inorder, postorder for tree in C++11

Please review my code for preorder, inorder and postorder of a tree. I am using C++11 (or wanted to use), so let me know if anything is deviating from the C++11 standard. ...
2
votes
1answer
77 views

Binomial heap in Java

I have this implementation of a binomial heap providing insert, decrease-key and extract in logarithmic time. MinPriorityQueue.java: ...
2
votes
1answer
23 views

Walking and comparing contents of binary trees

I've written a solution for http://tour.golang.org/concurrency/8, which asks for a Walk() function to traverse a randomly generated binary tree, and a ...
4
votes
3answers
454 views

Recursive binary search tree

How is my usage of std::unique_ptr() and std::move()? How can I improve this code? ...
1
vote
3answers
225 views

Tree parent and child nodes

I have this method that returns true if attribute is already used and false otherwise: ...
2
votes
0answers
26 views

Basic Binary Tree in Go

As an exercise I have written a basic binary tree implementation in Go. Tree struct: ...
3
votes
0answers
84 views

Kruskal's algorithm in Java

I have this Java implementation of Kruskal's algorithm. It solves a tiny problem instance correctly, yet I am not quite sure, whether my implementation is correct. The code as follows: ...
1
vote
2answers
44 views

Parse a tree & return the various paths

Input: { 1: [2,3], 2:[4], 3: [5,6], 4:[6] } Expected output: [[1, 2, 4, 6], [1, 3, 5], [1, 3, 6]] My Code: ...
2
votes
2answers
63 views

Find the size and depth of a tree

I have tried to implement two methods, one for finding the size of the tree and the other for finding the height of the tree. Can they be optimized further? ...
5
votes
1answer
84 views

Find all the paths of tree that add to a input value

This code is attributed to Stack Overflow itself here. The path which adds to the sum, which need not be starting from the root, not be ending at the leaf, i.e. a path can be between root and a leaf. ...
3
votes
1answer
73 views

Convert binary tree to doubly linked list

The code works and I get the results I want. Please comment about complexity, a shorter way of implementing the solution, and advice for better unit tests. ...
5
votes
1answer
61 views

Create a tree recursivly

I want to create a Treeview in C# which will group file by prefix (here the prefix is a marked by the separator _). The following files should give this tree: ...
6
votes
2answers
100 views

Tree traversal into List

The interview question was to traverse a tree into a list. ...
3
votes
0answers
30 views

2 4 tree insert function

I'm after creating an insert function for a 2 4 tree in Haskell. I'm just wondering if this is the best way to implement it (especially when handling the Root4s), ...
3
votes
1answer
81 views

Deepest node in tree

I have written two classes, one to represent the tree and a Util class to get the deepest node from the tree. Can you please review the code? Below is the class ...
5
votes
2answers
97 views

Hash Binary Tree Map

I made a map based on a binary tree ordered by hashcodes, with collisions fixed with equals(). Are there any improvements I could make? ...
5
votes
1answer
69 views

Simplifying a class template

I wrote this code over night for a little project that my friend and I have been working on. This class template was created over a year ago during as a class assignment for C++ programming. I ...
4
votes
3answers
217 views

Design of a N-ary tree

A friend of mine and I recently started a project and at this moment we are writing a common library. He began writing an N-ary three and he is convinced that he has the best design with which I am ...
10
votes
1answer
98 views

Matrix to Tree Algorithm

The code takes a matrix and turns it into a tree of all the possible combinations. It then "maps" the tree by setting the value of the ending nodes to the total distance of the nodes from beginning ...
3
votes
1answer
61 views

Managing tree nodes

I have complex logic manage EnvDTE.Project and EnvDTE.ProjectItem for a VS Addin (VS 2010). I would like elegant, easily maintainable code that follows DRY and KISS principles. Maybe using helper ...
3
votes
2answers
332 views

Better way to find the maximum value in a Binary Tree

I have to find the maximum value in a binary tree. This is how I did it iteratively: ...
2
votes
1answer
46 views

Construct the tree from a list of edges

I was using the following code to construct the tree from a list of nodes: [1, 2] means that there is a bi-directional link between ...
3
votes
2answers
141 views

Binary Search Tree in C++

I'm writing C++ for the first time and wanted to implement a BST. I come from writing C, so I tend to write code in that way. I'm trying to wrap my head around smart pointers, but can't seem to get ...
3
votes
3answers
170 views

AVL tree for inserting and searching

I have made an AVL tree. It works and does what it needs to do. I only need it to insert and search. I am comparing how long it takes to load and search a dictionary file in relation to other various ...
1
vote
2answers
125 views

Octree code performance

I'm using a simple Octree in my program, wanted to know if my implementation could be faster. It is part of this program: https://github.com/Mortis69/rendera Octree.H: ...
3
votes
0answers
57 views

Treap with implicit keys

I implemented an implicit treap and tested it a little. It works fine but I'd like to know if there are ways to improve/simplify things and/or if some parts are incorrect. Later, I'll augment code to ...
1
vote
1answer
35 views

insertBST exercise

I'm just learning Haskell on my own, and did an exercise to implement insertBST. Is this idiomatic Haskell? ...
0
votes
0answers
31 views

Implementing Functor Instance for `ITree`

Looking at this Typeclassopedia exercise, I typed out foldTree on the following type: ...
0
votes
0answers
63 views

Freeing a binary tree data structure in C

I have this function that I hope to be a good alternative to the recursive (thus performance expensive) approach. ...
18
votes
2answers
491 views

Where equations are born and mutants are buried

I've read up on genetic programming yesterday so I figured I'd try to implement something myself. I would like the main focus to be on whether or not I've implemented the idea behind it correctly. ...
4
votes
1answer
190 views

Implement `fold` on a “Rose Tree”

Given the following algebraic data type, a Rose Tree: data Tree a = Node { rootLabel :: a, subForest :: [Tree a] } I attempted a ...
1
vote
1answer
151 views

Trinary tree insertion and deletion

I have worked on the trinary tree problem insert and delete. Can anyone look at it and tell me how it is? TrinaryNode.java ...
5
votes
3answers
450 views

Building a parent/child tree relationship

I have a problem: build a tree relationship parent/child like this one: Can you review this piece of code please since I am convinced it could be improved? ...
1
vote
2answers
73 views

Binary search tree with templates

I am currently attempting to become proficient in C++ and started by implementing a basic binary search tree. Most of the programming I have done is in Ada, Python and C. I would like to be able to ...
5
votes
1answer
103 views

Time Limit Exceeded for Code Chef problem Rendezvous [closed]

I am trying to solve a problem Rendezvous in code chef. Problem Statement: Given number of cities and routes between them resembling tree, consider there are two people who are put into ...
3
votes
0answers
15 views

Searching a Join List for an index Attempt #2

Originally I posted this incorrect attempt - Searching a Join List for an index. Given a JoinList: ...
4
votes
2answers
65 views

Make a map using a splay tree

In my data structures and algorithms class, we were introduced to the splay tree, a BST with the additional property that recently accessed elements are quick to access (because they stay at the top ...
5
votes
2answers
138 views

Finding the weight of the heaviest path in a binary tree

I'm fairly new to Java, arriving in the "future" from C and returning to type safety from Python. I've programmed an algorithm to return the weight of the heaviest path from the root of a binary tree ...