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.
0
votes
0answers
5 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
17 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
27 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:
...
1
vote
2answers
258 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 ...
7
votes
0answers
106 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 ...
0
votes
1answer
14 views
4
votes
2answers
53 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
43 views
0
votes
1answer
31 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
362 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
36 views
10
votes
1answer
93 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
235 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
76 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
61 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
48 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
203 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
167 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
35 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
256 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
78 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
27 views
Turning a 2D array into a tree
I have the following data structure that's obtained from a third party:
...
12
votes
2answers
287 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
66 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
61 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
87 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.
...
3
votes
1answer
52 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
108 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
91 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
90 views
Binary tree implementation in Scala
This is my implementation of a binary tree in Scala. How can this be made better?
...
3
votes
1answer
47 views
Ordered map for C using AVL tree
I was in the mood for some data structures and I decided to code up an ordered map using AVL tree. I will post only map.h and ...
2
votes
2answers
148 views
Breadth-First Search heuristics to find solution to Water Jug Challenge
I started learning AI recently. In AI, searches should be avoided and everything in AI is a search problem.
One of the easiest problem where we could use general AI search techniques is the water jug ...
7
votes
1answer
187 views
Are AVL trees equal?
I was inspired by this answer and decided to implement an AVL tree with the methods equals and hashCode as if I was asked to do ...
2
votes
0answers
58 views
Efficient Sets and Maps with Treaps
I wrote up a Treap implementation to serve as the base class for a bunch of augmented data structures (interval sets, plane (2D) sets, order statistic trees), replacing my RB-tree base.
Some ...
6
votes
3answers
133 views
BST C++ STL implementation, visiting algorithms
I am currently learning C++, and as an exercise I tried to implement a BST in a C++11. I am not sure at all if what I have done could be considered a good example of c++ programming, thus I would love ...
8
votes
3answers
117 views
Check if all leaves are at same level in a binary tree
I have written this code for checking whether all leaves are in the same level or not, in a binary tree. Any suggestion or improvement is appreciate.
...
-1
votes
1answer
34 views
Is my Binary tree correct?
I have been watching this video:
https://www.youtube.com/watch?v=M6lYob8STMI
And here is the code of it in groovy (just the add method):
...
5
votes
3answers
114 views
Every node in binary tree = sum of subtree
I wrote this in Java (I know that the brackets don't exactly follow the standard way of doing it in Java - so it looks a bit like C#). But I was wondering how this algorithm is percieved. I have seen ...
2
votes
0answers
41 views
Printing a binary tree in vertical strips
I'm trying to print a binary tree in vertical strips.
For instance, a tree like this:
8
/ \
6 10
/ \ / \
4 7 9 12
/ \
3 5
...
3
votes
1answer
77 views
Binary search tree implementation with Rule of Three
I am started to code in C++ and tried to implement a simple BST data structure. Since at the moment I am learning about the Rule of Three, I tried to implement it in my code. Yet, I realise that my ...
5
votes
2answers
60 views
Binary search tree methods
I have implemented a binary search tree with the methods search, insert, and delete. I want to know if this is the best way to code them or if there are any other way by which I can reduce the code ...
4
votes
1answer
68 views
Red-black tree not matching performance of Java's TreeMap
This program is for constructing a symbol table where a key is a word and value is the frequency of the word in a text file and finding the word with maximum frequency.
I did it in two ways:
First I ...
5
votes
0answers
60 views
Mapping a file system to a tree structure
I need to write a very basic file/directory browser. The data structure I'm using is pretty simple - a Node with an optional parent and children. Along with the data structure I also need a simple ...
12
votes
4answers
1k views
Binary Search Tree - C++
I'm implementing several data structures in an attempt to learn C++. Below is a binary search tree that I've implemented to learn about pointers, dangling pointers, and memory leaks. I was hoping ...
4
votes
2answers
61 views
Binary Search Tree in Java
Please give me some feedback on how I could make it better or simpler.
...
5
votes
5answers
186 views
Enumeration of random trees
I'm interested in recursive generation of trees in Python. For my eventual application, it's important that the trees be represented as a list of nodes (rather than say a dictionary, or an edge list, ...
2
votes
0answers
47 views
Range Query - Range Update
In most of the range query-update questions, we are asked to update some range of the array with some constant_value which can be done using the segment-tree ...
3
votes
4answers
171 views
Snippet of an easy binary search tree
ALL I want to do is making binary search tree, inputting there from users, and then print out data in each node one by one according to the user's selection (whether he choose to print the data in the ...
4
votes
3answers
137 views
Binary search tree implementation (with Node class)
I have implemented the Binary Search Tree in Java and would love to get reviews. I would like to have some comments on multi thread implantation.
Note: Corrected Code is in the Answers
...
4
votes
3answers
815 views
Recursive Level Order traversal
I have come up with this code to do level order traversal recursively for a binary search tree.
...