Questions tagged [tree]
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.
889
questions
2
votes
2
answers
2k
views
Initializing a multi-tree data structure
I wrote this code to read text of a file and use it to initialize objects and place them in a multi-tree data structure. The multi-tree has the base node as an object called ...
1
vote
1
answer
152
views
3
votes
2
answers
1k
views
Binary Tree Operations
I've been programming for about 5 years now, mostly in C++ and Java, while continuing my college education in Computer Science. As an adult student, I'm always looking for opinions and ways to improve ...
5
votes
1
answer
645
views
Tree heap Haskell code
I'd like a review of Haskell tree heap code in Turning a tree into a heap in Haskell.
...
5
votes
5
answers
4k
views
Check if a Binary Tree <String> is aBinary Search Tree
I'm understanding the question, but I want to know whether or not my implementation is correct.
The question is:
Write a method that accepts as its argument a BinaryTree object and
returns true ...
1
vote
1
answer
2k
views
Making a tree with hash input
I initialized a tree using a nested hash as input, but when I recursively call Tree.new on the children, it doesn't seem to pass each child as a hash. As a pretty ...
5
votes
1
answer
2k
views
Orthogonal range search for a static kd tree
I'm trying to optimise my implementation of a static kd tree to perform orthogonal range searches in C++.
My problem: The code performs slowly even for a small number of queries when the number of ...
3
votes
1
answer
454
views
Expanding branches of a family tree
I'm making a family tree. The following script allows the user to expand branches of the tree. It works fine, but there must be a better way.
You can see it working here.
...
4
votes
1
answer
5k
views
Recursive search to delete n'th child in tree
I have to implement a tree programming here. What I mean by tree programming is I have data stored in tree format. I have a parent object which will have child objects of same type the level of ...
2
votes
2
answers
11k
views
Tree node filtering with List<TreeNode>
I had a question about filtering tree view and returning just first match.
I've tried to create list<treenode> and change the code. Is it possible improve ...
2
votes
1
answer
2k
views
Iterative implementation of alpha beta tree search
This is an iterative implementation of alpha beta tree search in C#. Please help me confirm the correctness of my code. search() is called when the search begins.
<...
3
votes
2
answers
1k
views
BinaryTree class with extra methods
I am taking a data structures course. I would like to check whether my BinaryTree code is perfect, fine or has lots of mistakes.
I would like any kind of advice ...
8
votes
1
answer
53k
views
Binary search tree implementation in C++
I've written a BST implementation and would like a code review and any suggestions on how to make it better.
...
3
votes
1
answer
3k
views
Dictionary tree optimization
I was wondering if anyone could give me a little bit of help with optimizing a tree-structure in C++. I'm currently developing a dictionary program for a school project but want to take it a bit ...
5
votes
1
answer
240
views
Improving General Algebraic DataType type-safe code for AA trees
As an exercise on GADTs I wrote a type-safe implementation of AA trees. I'm quite happy that the AANode data type correctly grasps the properties of the tree. Just ...
1
vote
2
answers
227
views
Die-rolling for ordering
I have a little experience with Python and am trying to become more familiar with it. As an exercise, I've tried coding a program where the ordering of a list of players is determined by the roll of a ...
4
votes
2
answers
66k
views
Deleting a node from a binary search tree
I have read about it at a few places and tried to write my own version. I would like to get it reviewed.
...
6
votes
1
answer
6k
views
Tree-traversal without recursion
I wrote the following code for printing all the paths to the leaf nodes in a tree (NOT a binary tree ) without using recursion. I have used a stack and performed dfs on the tree. Whenever I reach a ...
1
vote
3
answers
6k
views
Implement a function to check if a tree is balanced
Yet another interview question:
Implement a function to check if a tree is balanced. For the purposes of this question, a balanced tree is defined to be a tree such that no two leaf nodes differ in ...
2
votes
2
answers
5k
views
Splay tree implementation
I am looking into splay trees and I implemented a version. It seems correct. Could someone please let me know if this indeed correct and how to improve it?
I will just show the ...
7
votes
1
answer
10k
views
C++ tree base node
I've been programming in C++ again (after switching to web languages) for about 2 weeks now. I wrote this simple Node class from which all other objects within the ...
15
votes
3
answers
3k
views
Quadtree design
I have an application which is used for displaying and modifying huge volumes of point cloud data from lidar files (up to few gigabytes each, sometimes loaded in simultaneously). In the app the user ...
3
votes
2
answers
3k
views
Tree Node class - deallocation in the destructor
Is my destructor correct? Does it properly deallocate the subtrees?
...
13
votes
1
answer
483
views
Is this a BSP tree? Am I missing something?
I've been practicing using BSP trees as I hear they are a good start to create procedural spaces such as houses.
For ease-of-deployment purposes, I've tested this code in Lua and it seems to work. ...
6
votes
3
answers
375
views
Finding the sum of the digits appearing in the leaves via in-order traversal
The following text is an in-order traversal of a binary tree with 1023
nodes. What is the sum of the digits appearing in the leaves?
How can I improve this Clojure code? It looks strange to me to ...
6
votes
1
answer
331
views
Tree/array mashup
I'm currently trying to prove a data structure which I've created to speed up lookups for integral keys. The specific case I have in mind has the following usage case:
At start is populated with n ...
14
votes
1
answer
2k
views
Prim's algorithm for minimal spanning trees
I want to write an article giving a Haskell introduction specifically to Java developers, and would like to get feedback on my implementation. Please keep in mind that I don't want to be "too clever", ...
4
votes
1
answer
3k
views
Traversing a BST in iterative inorder
Traverse a binary search tree in iterative inorder.
Note that the iterative methods below contain the meat of the code; the remaining code is included for completeness.
...
9
votes
1
answer
5k
views
Binary tree in Python
As a Python newbie, I have coded this binary tree as best as I could to follow Python
idioms. However, I know it is still very verbose and not up to standard. I would like Python experts to tear this ...
2
votes
0
answers
1k
views
Union-set intersection-set for a binary-tree implementation of sets
From SICP:
Exercise 2.65
Use the results of
exercises 2.63 and 2.64 to give (n)
implementations of union-set and
intersection-set for sets implemented
as (balanced) binary trees.41
I ...
11
votes
1
answer
4k
views
Small C++ Boost extension based on boost::property_tree
This is a small extension based on a boost::property_tree, which supports arbitrary values for the properties and appropriate serialization. It can be used as an ...
4
votes
1
answer
3k
views
Finding the k-th element in a BST
Given a Binary Search Tree, determine its k-th element in inorder traversal.
Here's my node structure:
...
4
votes
1
answer
1k
views
Abstract tree-map function
Exercise 2.31. Abstract your answer
to exercise 2.30 to produce a
procedure tree-map with the property
that square-tree could be defined as
...
11
votes
4
answers
3k
views
Composite and Visitor patterns for tree-based survey functionality in C#
I have written some survey functionality for a project. Basically, a generic survey form that can be composed of sections and questions.
I have a Survey class, <...
5
votes
1
answer
6k
views
TreeMap implementation
I've just tried to do some code for TreeMap. The TreeMap concept can be found here. As an exercise I've tried to find the ...
6
votes
2
answers
480
views
Optimising a custom tree data structure
I have the following 'custom' tree data structure. This concept was to be thought of as, if given ("abb", 20) and ("abc", 30), then
Tree['a']['b']['b'] == 20
<...
6
votes
2
answers
652
views
"File Fix-it" challenge
I'm learning Python and have found this problem from Google Code Jam:
How many mkdir commands does it take to construct a given directory tree:
Input
The first ...
9
votes
4
answers
7k
views
Basic folder tree with a list of strings
I am building up a basic folder tree with a list of strings in the form /root/node/node/node. Here is the basic algorithm I am using currently to build this collection and fill in my ...
12
votes
5
answers
3k
views
Binary tree encoding
I implemented a solution to this coding challenge on the Code Golf. I have decent experience with C/C++, but it's been a while since I've used them extensively.
...