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

9
votes
1answer
59 views

Maximum element in a binary tree

This method finds the maximum in a binary tree. I have used generics to make this code more usable. However, I am not sure if I have written efficient and good Java code. This is a method inside a ...
3
votes
2answers
53 views

Python Tree/Node Class from scratch

I decided to try to make my own tree style class. I may use it in a project, but it's primarily to practice. I would appreciate any feedback for improvements, best practices, etc. ...
6
votes
2answers
248 views

C# FTP class for interaction with FTP server (Download only)

I'm writing my own FTPclient for downloading files from my FTPserver as a project. So far I can download and go backwards/forwards in the folders using this code. How does it look? What could be done ...
7
votes
2answers
42 views

Function to find the minimum depth of a tree

For a leetcode problem to find the minimum depth of the binary tree, I have written the below solutions. The solution is accepted, but can I do any other changes to make the code elegent? ...
1
vote
0answers
36 views

Dictionary operations on a Binary Search Tree data structure?

today I tried to code all the dictionary operations such as Search, Successor, Predecessor, Minimum, Maximum, Insert, Delete etc. for a Binary Search Tree data structure using the Java programming ...
4
votes
1answer
65 views

Binary Search tree deletion optimization

I have just started implementing Binary Search tree on my own without using any tutorials online. Please have a look and suggest how can I make code less cluttered and more faster. Right now I am ...
2
votes
0answers
30 views

Coloring trees in Elixir

The following is my tree coloring realisation attempted to get a feel of Elixir (simple, but slow coloring algorithm from Principles of Distributed Computing). Coloring runs from the root, using ...
4
votes
3answers
206 views

Python function to determine whether a given BST is valid

Here's a simple function I wrote using recursion. Does this run in \$O(n)\$ time and use \$O(n)\$ space, where \$n\$ is the number of nodes in the tree? ...
4
votes
1answer
60 views

Iterative Red-Black Tree (dynamic stack)

I've completely reworked the previous code, posted here, so that it is a bit more correct regarding dynamic memory management, and also a bit more true to the object-oriented paradigm. ...
1
vote
1answer
47 views

Coding And Binary Tree implementation C++

When searching for information about the Binary Tree, the code on people's blogs are complicated, so here I'm trying to code a very simple Binary Tree. Am I missing anything? Is there a better way I ...
4
votes
2answers
125 views

Memory management for Red-Black Tree

I've written this program yesterday, and I was reminded why I dreaded C++ before turning to Java: pointers and associated terms (like destructors, initializations and copy/move constructors) are ...
3
votes
1answer
65 views

Binary trees in Rust: more iterators! (non-consuming variant)

This is a follow-up to Binary trees in Rust: iterators, where Shepmaster suggested that I implement a non-consuming iterator. This was relatively straightforward. I chose to mirror the design of the ...
3
votes
1answer
67 views

k-d tree implementation in C++11

I've written a k-d tree implementation in C++11 in order to learn and practice the finer points of the language. I'd appreciate feedback on the code, e.g. is it good C++ code, missing functionality, ...
5
votes
1answer
65 views

Binary trees in Rust: iterators

This is a follow-up to Basic binary tree manipulation in Rust, where Shepmaster suggested that I implement the Iterator trait for the binary tree. This ended up ...
4
votes
1answer
45 views

Basic binary tree manipulation in Rust

The goal here is to implement a basic binary tree with values only on leaves, with depth, mirror, and ...
6
votes
1answer
49 views

Saving and resuming position while iterating over a container

Background: I'm in the process of writing a relatively simple behavior tree driven AI system for a game that I'm working on. Basically, the behavior tree is made up of individual gameplay tasks ...
3
votes
0answers
81 views

Specialty tree structure - BK Tree

I've been working on a implementation of specialty tree structure called a BK-Tree (more here and here). Basically, it's a tree that allows relatively efficient querying for items within a specific ...
5
votes
6answers
136 views

__repr__ for a binary tree whose constructor has default arguments

I recently have been working on a BinaryTree class, and looked into creating a proper __repr__ which when eval'ed would recreate ...
8
votes
1answer
380 views

Implementing a fast DBScan in C#

I tried to implement a DBScan in C# using kd-trees. I followed the implementation from here. ...
1
vote
2answers
63 views
2
votes
2answers
56 views

Count number of matching nodes in a Binary tree

Problem Count the number of matching nodes in the subtree rooted at some node n. Solution ...
1
vote
0answers
49 views

Print all possible sequences that could have created this BST

I was working through Cracking The Coding interview, and I couldn't wrap my brain around their solution to one of the problems, so I ended up coming up with my own that, IMHO, is a lot cleaner and ...
1
vote
0answers
74 views

AVL tree implementation

So I've just created an AVL tree in Java. However when I test its running time using the following code: ...
3
votes
2answers
436 views

Binary tree data structure

I am learning about the binary tree data structure and implemented some basic functionality. It was working great with module level functions until I realized that I need to keep track of the root ...
13
votes
1answer
191 views

C# Treap implementation

I recently developed a simple treap data structure in C#. In the future, I may have the class extend IDictionary. For now, I only expose a public accessor and a ...
1
vote
1answer
19 views

Implementing BST in javascript

Is this an efficient and clean implementation? ...
4
votes
3answers
100 views

Implementing N-ary trees in C

Looking at my code, I feel like it is not instantly clear for someone who did not write it. I feel like readability will be important for me in the future, if I'm ever to write code on an ...
2
votes
1answer
47 views

Optimizing binary search tree

How could I optimize this binary search tree? ...
0
votes
1answer
35 views

Taking a node in rootA and finding a clone node in other tree

I was asked this as an interview question. I was also asked to assume that there is a function which can compare and say two nodes are identical. I would like to implement that function as well. I'm ...
7
votes
3answers
412 views

Determine if a binary tree is balanced

I'm currently running through some Cracking the Coding Interview questions and my solution to 4-4 is quite different from any of the given solutions. The question asks to determine if a given binary ...
3
votes
1answer
41 views

Printing a BST tree level-by-level

Please review and tell me what improvements can be made: ...
10
votes
1answer
138 views

In-memory B-Tree in C++11

I just wrote a simple B-Tree insertion implementation, and was wondering if anyone can comment / critique on code style, readability, maintainability etc. I tested it with a few small test cases and ...
6
votes
2answers
242 views

Search on List<Tree-like structure>

I create a data collection system that has a tree-like structure built on the similarity to the pattern of the factory, and I have the difficulty in working with this structure, more stingrays lot of ...
0
votes
1answer
84 views

Sorting a Binary Tree

I have written a simple binary tree using structures and a couple of functions in order to add, search, find the minimum and maximum values, remove a node as well as destroy the node, the problem is ...
2
votes
0answers
68 views

Trinary Search Tree

I'm probably not the first to think this up, but here we go. An trinary search tree is a generalization of a binary search tree in the sense that instead of a comparison function returning true or ...
2
votes
1answer
145 views

Traversal of a tree in a top-view order

I was trying to solve this problem. Problem Statement You are given a pointer to the root of a binary tree. Print the top view of the binary tree. You only have to complete the function. ...
3
votes
2answers
380 views

Path sum in binary tree

Root to leaf path sum equal to a given number Given a binary tree and a number, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals the ...
4
votes
5answers
230 views

DFS in Binary Tree

I have written this code for DFS in a binary tree and would like improvements on it. ...
2
votes
1answer
71 views

Create a Tree Node from JavaScript Array

I'm trying to create a list of subpaths from a flattened array. Here's the starting point: ...
8
votes
1answer
311 views

Generic domain independent Monte Carlo Tree Search methods library

I've written this small generic library for the purpose of my Bachelor's thesis. It's fully functional and unit tested and I want to get as many opinions as possible regarding overall code quality ...
1
vote
0answers
89 views

Red-Black Tree (2-3-4 node tree) map implementation

Here is an implementation of a red black tree that I made. I am pretty sure it's working fine though I may have overlook something. How can I improve it in any way possible? Interface: ...
1
vote
0answers
43 views

Turning a 2D array into a tree

I have the following data structure that's obtained from a third party: ...
12
votes
2answers
351 views

The median of the given AVL tree

A long time ago I found this question and asked about an algorithm here. My code is also available on GitHub. Given a self-balancing tree (AVL), code a method that returns the median. ...
1
vote
0answers
73 views

Getting branches of a tree

Given a tree structure (in this example it a list of some nested group nodes), what is the best way to get all branches (branch = list of nodes from root to the leaf element)? My solution (here root ...
2
votes
0answers
168 views

Building a tree structure from pairs of parent-child to retrieve all ancestors of a leaf

I am trying to build a tree similar to this one : 1 / \ 2 3 /|\ 4 5 6 / 7 With that tree, I must be able to get all ancestors for each ...
7
votes
1answer
138 views

Search iteratively in a ternary search tree

I was trying to write an iterative search function for my Ternary Search Tree class based on a pseudo-code, and now it seems to work, but I think it can definitely be improved. ...
4
votes
1answer
61 views

Factory that creates a complex object tree

I've got a complex object tree that I need to instantiate. The object tree is a bunch of specialized classes that don't have a common root object (other than Object) and has generic objects (that I ...
8
votes
2answers
111 views

My own version of a search binary tree

I wrote my own version of a search binary tree in Java. Could someone kindly review it? ...
1
vote
0answers
188 views

AVL tree implementation in Java

Please ignore the OOP aspects of the code for a moment and concentrate on the efficiency of code. I would be obliged if someone could suggest a way to shorten my AVL tree implementation, such as using ...
5
votes
1answer
224 views

Binary tree implementation in Scala

This is my implementation of a binary tree in Scala. How can this be made better? ...