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.
2
votes
0answers
15 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 ...
2
votes
0answers
31 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
34 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 ...
3
votes
0answers
21 views
Binary tree implementation in Scala
This is my implementation of a binary tree in Scala. How can this be made better?
...
-1
votes
0answers
41 views
Inverting a binary tree [on hold]
So I came across some code which is used to invert a binary tree, and it looks like this:
...
3
votes
1answer
44 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
99 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 ...
6
votes
1answer
148 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
40 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
113 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
100 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
29 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
94 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
38 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
71 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
52 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
58 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
47 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
970 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
50 views
Binary Search Tree in Java
Please give me some feedback on how I could make it better or simpler.
...
5
votes
5answers
168 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, ...
1
vote
0answers
33 views
Range Query - Range Update
This is the problem statement:
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 ...
3
votes
4answers
166 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
117 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
259 views
Recursive Level Order traversal
I have come up with this code to do level order traversal recursively for a binary search tree.
...
7
votes
2answers
125 views
Traversing binary trees through and through
Given a binary tree, it's quite common to perform some operation on all nodes while traversing pre-order, in-order, post-order or level-order, depending on the task at hand. For example you might want ...
5
votes
4answers
639 views
Simple Binary Search Tree
At the moment I am learning algorithms and here I am trying to implement a simple binary search tree. I would like to know your suggestions on whether I am on the right track or not, and how this can ...
2
votes
0answers
25 views
Improving my build_max_heap algorithm [closed]
I'm new to such complicated (for me) data structures as binary trees now. I think I've made many mistakes in my build_max_heap algorithm and it can be improved. The rule I'm using is that smaller ...
2
votes
0answers
71 views
XML to JTree app needs Model/View/Controller refactoring
I'm developing a JavaSE-1.7 Swing application that displays XML files as a JTree. This will be the base for further work, e.g. filtering nodes.
My questions, as a ...
4
votes
1answer
204 views
Swap nodes in a binary tree
I solved this challenge. It passes all the test cases, but I'm not very happy with my solution. I'm convinced this could be done much smoother (i.e less code)
Swap operation: Given a tree and a ...
1
vote
1answer
93 views
A binary tree , its copy constructor and assignment operator
I implemented a binary tree in the following code. Its node's copy constructor and assignment operator should copy itself and all its descendents. Similarity a node's destructor should delete itself ...
4
votes
2answers
75 views
Checking if a tree is balanced or not
I was writing this code to check if a tree is balanced or not and I ran into a situation where I would have liked the method to return 2 values at each step. First to signify whether the tree is ...
4
votes
0answers
71 views
Equivalent binary trees (A Tour of Go)
Any suggestions on how to improve the code shown below for the Go-tour exercise?
Exercise description:
There can be many different binary trees with the same sequence of
values stored at the ...
2
votes
1answer
78 views
Doing tree search in Java
I have this tiny library for building unbalanced, binary trees and doing tree search on them. I tried hard to define a generic API that would allow custom implementations of trees.
...
2
votes
1answer
137 views
Treesort in Java
I have this sorting algorithm which constructs an (unbalanced) tree and performs in-order traversal in order to sort the requested range. However, the more order exists in the input array, the closer ...
5
votes
1answer
167 views
Given a binary tree, compute the min depth of a leaf node
Here is the source of the question. They don't require a tree to be a BST, but my tree is. The algorithm would be the same for a simple binary tree.
And there are two implementations:
A recursive ...
4
votes
0answers
77 views
Functional tree iteration in Common Lisp
I'm adding some functionality to an existing library of data structures in Common Lisp, with a view to asking the original author if I can take over maintenance and development of it. While the ...
3
votes
1answer
240 views
Creating a menu as nested unordered lists from JSON data
I have a JSON input using which I have written below function to recursively create an unordered list.
Is there more precise way to achieve it?
...
2
votes
2answers
60 views
Algorithm that checks if a tree is full and complete
I am trying to write a method that will return true if a binary tree is full and complete (each node has 2 children or none and all the leaves of the tree are at the same depth).
My idea is to use ...
4
votes
2answers
136 views
Change one word into another by picking words that differ by one character
There is a file with two words with the same length. Call them first and last.
Also there is a file - dictionary with a lot of different words.
The task is to find shortest chain of words from ...
0
votes
1answer
37 views
Adding a node to a Binary Search Tree and printing the path to it
I wrote BST insertion code with the book. The book uses recursion, but I just want to know how I can do it without recursion.
My code is working, but I don't know if it is correct.
...
-1
votes
2answers
110 views
2
votes
2answers
293 views
8
votes
3answers
352 views
Suffix tree implementation in Java
I was trying to solve the problem where given a larger string and an array/list of smaller string, we need to make the determination whether the larger string contains each of the smaller strings. I ...
0
votes
1answer
63 views
Iterative tree traversal to turn tree into a dictionary and list
I am trying to iteratively turn a tree into a list.
For example:
c1
c11 c12
c111 c112
The tree above ...
0
votes
2answers
29 views
Binary tree isSame()
Please help me review this code. I want to make it both accurate and more Go-styled.
Go Playground code
...
1
vote
0answers
33 views
Recursive way to find Inorder successor
So far I have attempted to find the inorder successor through recursion and it seems to be working right. Can someone review the below code and give suggestions.
...
2
votes
1answer
98 views
Huffman code generator in Haskell
This is problem 50 in https://wiki.haskell.org/99_questions/46_to_50. The website has more elegant Haskell solutions, but I wanted to get feedback on how the code I wrote on my own below could be ...
7
votes
2answers
164 views
Search for Tree
Here is a search implementation for my tree. It searches each node in a breadth-first manner first, but it goes deeper in a depth-first manner, in the event it needs to go deeper. I know there may ...
3
votes
2answers
123 views
C# Tree implementation
I’m working on a C# implementation of a tree class.
The tree will be used wherever I need to store data in a tree format. (Application Menu, File Infos etc.). Therefore the tree should support a lot ...