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
1answer
27 views

Speed concerns of octree implementation

For couple of days now I am trying to speed up my Force-Directed graph implementation. So far I've implemented Barnes-Hut algorithm that's using octree to decrease number of computations. I've tested ...
0
votes
1answer
26 views

Follow-up zp-Tree to represent Trees as nested arrays: 3rd (final?) revision

This is a follow-up on my previous post. I have made modifications based on the feedback received on the previous post, hence I request a third (final?) review on the modified code if ok. Note: ...
0
votes
1answer
18 views

Follow-up zp-Tree to represent Trees as nested arrays

This is a follow-up on my previous post. I have made modifications based on the feedback received on the previous post, hence I request another review on the modified code if ok. Note: review ...
1
vote
1answer
34 views

Storing hierarchical data into a data structure

With the following data in a table, ...
1
vote
1answer
38 views

zp-Tree library to represent trees as nested arrays

For my project I have rewritten a small lib for a tree structure that was inspired by wangzuo's js-tree. The reason was largely because I prefer to work with an array structure rather than nested ...
0
votes
0answers
16 views

Lazy segment tree implementation

I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially the ...
0
votes
0answers
36 views

Segment tree implementation in C++

I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, not "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially ...
3
votes
3answers
130 views

Building prefix tree from dictionary, performance issues

I'm trying to build a prfix tree. So, using the following dictionary 'and','anna','ape','apple', graph should look like this: I've tried 2 approaches: using ...
1
vote
0answers
42 views

Binary search tree class in Java

I am trying to create a binary search tree class in Java and am wondering how I did. I am fairly confident on most of the methods, but fear I may have messed up the delete method. I know I am ...
3
votes
0answers
59 views

Check if a binary tree is a binary search tree or not

This checks if both the left and right subtrees are binary search trees. If they are, then it compares the nodes data with the maximum element in the nodes' left subtree and minimum element in the ...
2
votes
1answer
27 views

Verify that a binary tree is balanced

A binary tree is balanced if both its children are balanced and the difference between the heights of its children is at most 1. ...
4
votes
1answer
73 views

Implementing Binary Tree using Queue in C#

I am in the process of learning data structures and I am trying to implement Binary Tree using Queue in C#. Below are my Tree implementation classes. ...
0
votes
2answers
67 views

Summing all keys in the leaves of a tree

My program takes 35 sec to run example 2. How can I make my program faster? ...
0
votes
1answer
40 views

Common ancestor in a binary tree

This method finds the common ancestor of two nodes in a binary tree. Any style suggestions or ways to make it more idiomatic? Is the algorithm correct? Rubocop says the cyclomatic complexity is too ...
1
vote
1answer
100 views

A basic pure Python hash map using a tree

I would like feedback on my first attempt to understand how hash tables work. I've read some on how hash tables use modulo operations to find the location of a key. Can you help me understand, ...
5
votes
0answers
44 views

B+ Tree Visualization in LaTeX/TikZ

I have written a LaTeX package to visualize B+ trees. The main purpose is to provide a simple but powerful package which provides a convenient interface. However, this is my first LaTeX package and ...
1
vote
2answers
45 views

Next node of a node in Binary search tree

To find the node next to a given node we need to consider two cases. case 1: if the node has a right subtree then return the min node in its right subtree. case 2: if the node doesn't have a right ...
0
votes
1answer
42 views

Create a binary search tree from a sorted array (increasing order)

Description: Since the input array is sorted, we can take the middle element of the array to be parent and recursively do the same on the left and right halves to create left and right sub trees of ...
0
votes
1answer
39 views

Create D lists of nodes where D is the depth of the binary tree

I have used a HashMap of ArrayLists to maintain the nodes at each depth. Also i maintained a depth at each node in the binary tree by using a HashMap that stores . While traversing the tree in a ...
3
votes
2answers
38 views

Simple Octree implementation

I've implemented a rather straightforward octree, but I don't feel that good about the coding style or some of the implementation. In particular, I use some nasty ...
0
votes
0answers
44 views

AVL Tree Array Representation

In a school assignment I'm supposed to create a program simulate insertion, deletion, count nodes, and delete tree algorithm and displays the traversal, level order, and array representation of it. ...
4
votes
1answer
43 views

Classification tree in Swift

As an effort to teach myself Swift as well as to get familiar with machine learning algorithms, I've been trying to implement common algorithms, starting with a Random Forest. This is, for the moment ...
1
vote
3answers
143 views

Priority Queue (Binary Search Tree) Implementation

I have made a Priority Queue implemented as a Binary Search Tree. I would appreciate comments related to optimization and proper functionality, but any comments/critiques are welcome. PQ.h: ...
6
votes
1answer
643 views

Breadth-first search on a tree in Python

The following code performs breadth first search on a mockup tree ...
1
vote
1answer
86 views

Find pairs in binary search tree in which sum of nodes keys is equal key

There is a task: Given a binary search tree of \$n\$ nodes, find all the pair of nodes whose sum is equal to a given number \$k\$ in \$O(n)\$ time and constant space. Please let me know if you ...
2
votes
1answer
52 views

Counting the number of increasing sub-sequences

The problem is to find the number of increasing sub-sequence of a string with only digit characters. Answer may be very large, so output it modulo 10^9+7. I have been able to get a O(n) solution ...
3
votes
1answer
64 views

Design of tree data structure

I am practicing for technical interviews and I am encountering a lot of problems relating to the tree data structure. I have gone through other posts that discuss about the tree data structure and ...
3
votes
1answer
64 views

Josephus permutation - follow up

Follow up of this question Changes: The pop_min function now panics if the tree is empty. Moved the size attribute to the ...
4
votes
1answer
89 views

Josephus permutation

This problem is taken from the book Introduction to Algorithms, Third Edition By Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein: We define the Josephus problem as ...
0
votes
0answers
43 views

Red-black tree rotation

I am unfamiliar C coding styles and I had an idea to use a function pointer for this given piece of code. Typically, would it be aligned with current C coding style to use function pointers here or ...
0
votes
1answer
43 views

Tree processing for series and parallel execution

I have a tree processing application where some of the nodes are "executed" in parallel and some in series. I managed to do this but I feel that the solution looks a bit "hacked up" and can be ...
1
vote
1answer
70 views

Binary Tree for integers

This code implements a binary tree for integers. How can I improve it? ...
2
votes
1answer
88 views

Java Tree Implementation

I wrote a simple tree data type in Java consisting of nodes which are themselves trees, and where each tree has its own list of children (not a binary tree). I plan on eventually using it in a minimax ...
4
votes
1answer
53 views

Construct binary tree from inorder and postorder traversal

The problem is taken from here. The tree is guaranteed not to have duplicate elements. My questions is, instead of creating new arrays leftInOrder, ...
1
vote
1answer
21 views

Binary Search Tree insert while keeping track of parent for node to be added - iteration 2

Follow up question to Binary Search Tree insert while keeping track of parent for node to be added I am implementing a red black tree for fun and am wondering how I should modify my basic BST ...
1
vote
2answers
68 views

Finding all root-to-leaf paths in a binary tree

The task is to return all root-to-leaf paths, given a binary tree (from leetcode). This is my approach. Take a helper array and a counter, keeping track of what has been traversed so far. If it is ...
0
votes
1answer
25 views

Binary Search Tree insert while keeping track of parent for node to be added

This question has a follow up question: Binary Search Tree insert while keeping track of parent for node to be added - iteration 2 I am implementing a red black tree for fun and am wondering ...
1
vote
1answer
38 views

Checking for items in sublists

Today I'll demonstrate a simple function that searches for a item in all sublists of a list. For this it uses iteration, and keep in mind that it can be slow because of this. How can I improve it? ...
0
votes
0answers
53 views

Printing binary trees

After writing this answer, I was inspired to try to design a more elegant solution to the problem of printing binary trees. And what better tool with which to seek elegance than Clojure? The ...
2
votes
0answers
72 views

An AVL-tree based order statistic tree in Java

I have this java.util.Set implementation that is based on AVL-trees, which implies that the set is sorted. However, it provides two additional operations: ...
1
vote
1answer
41 views

Check directed graph is tree or not

Here is my approach. 1. Checking there is no cycle.(Using BFS) 2. All nodes are connected. (visited) ...
4
votes
2answers
94 views
2
votes
2answers
59 views

Make binary search tree from sorted array

Here is my code for converting a sorted array to a binary search tree. Please review and let me know the improvements or some better way of solving this. ...
3
votes
1answer
77 views

C++ Template Binary Search Tree

I've been trying to improve my C++ skills as well as work on some general coding techniques so I've attempted to build my first binary search tree in C++ using templates. I've mostly done Java ...
3
votes
2answers
115 views

Finding if the tree is balanced or not

Can someone please review my code and let me know if there are some bugs or possible improvements? ...
1
vote
0answers
35 views

Persistent set (Red black tree) - follow up

Follow up of this question Things I changed: Fixed some typos Renamed variables and method to more descriptive names.(Eliminated 1 letter variables) Added static method ...
2
votes
1answer
80 views

Persistent set (Red black tree)

This is a partially persistent data structure using a red black tree. It will copy \$O(lg(n))\$ items for each remove or add operation. ...
6
votes
1answer
79 views

Alpha Beta Pruning Optimization

I made a class that would do alpha beta pruning on a binary tree of 40 degree. However there is a time limit on a single move of 30 seconds. I am to play against my professor and his opponent class. I ...
1
vote
0answers
34 views

TreeNode with nested super as parent

I found a way to use the JLS as a tree-structure (at least in let the parent-field disappear). Please ignore the main-method. It works, but from OOD would you say this is ok? ...