As of May 31, 2023, we have updated our Code of Conduct.

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.

Filter by
Sorted by
Tagged with
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 ...
Dustin E.'s user avatar
  • 123
1 vote
1 answer
152 views

Complexity Of Determining Tree is balanced?

...
MrA's user avatar
  • 333
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 ...
user2449512's user avatar
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. ...
Will Ness's user avatar
  • 1,006
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 ...
Sara's user avatar
  • 53
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 ...
John's user avatar
  • 113
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 ...
Ishan Bhatnagar's user avatar
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. ...
Bocker's user avatar
  • 33
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 ...
VIckyb's user avatar
  • 655
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 ...
masoud's user avatar
  • 121
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. <...
resgh's user avatar
  • 214
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 ...
malhobayyeb's user avatar
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. ...
Nikhil's user avatar
  • 81
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 ...
icdae's user avatar
  • 151
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 ...
Petr's user avatar
  • 3,070
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 ...
jlim's user avatar
  • 103
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. ...
daydreamer's user avatar
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 ...
newbie's user avatar
  • 63
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 ...
Lukasz Madon's user avatar
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 ...
user384706's user avatar
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 ...
Sparky's user avatar
  • 145
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 ...
Marian's user avatar
  • 251
3 votes
2 answers
3k views

Tree Node class - deallocation in the destructor

Is my destructor correct? Does it properly deallocate the subtrees? ...
Worryn Ashtrod's user avatar
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. ...
roger_rales's user avatar
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 ...
Zordak's user avatar
  • 91
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 ...
Nim's user avatar
  • 460
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", ...
Landei's user avatar
  • 6,972
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. ...
Ganesh's user avatar
  • 339
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 ...
Jacques René Mesrine's user avatar
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 ...
jaresty's user avatar
  • 2,233
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 ...
Yippie-Kai-Yay's user avatar
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: ...
Ganesh's user avatar
  • 339
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 ...
jaresty's user avatar
  • 2,233
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, <...
ngm's user avatar
  • 211
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 ...
nkint's user avatar
  • 518
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 <...
deceleratedcaviar's user avatar
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 ...
gkr's user avatar
  • 63
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 ...
pstrjds's user avatar
  • 452
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. ...
Daniel Standage's user avatar

1
14 15 16 17
18