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.
3
votes
1answer
20 views
Convert points into an octree
I set about doing it as a challenge (and it's still far from finished) but I hit lots of problems. The main one that caused most of them was it can't deal with even numbers (it can be ...
2
votes
1answer
65 views
Binary Search Tree in C
I have implemented a BST from scratch. My aim is to draft better code and understand some pitfalls which I may have overlooked.
It includes the following functionalities:
Insert a new item.
Find ...
0
votes
0answers
35 views
Finding common ancestor in a binary tree
Following is a Python program I wrote to find the common ancestor in a binary tree (not BST) with no link to parent node. Please review.
...
3
votes
1answer
63 views
Python Longest Repeat
I am trying to find the longest repeated string in text with python, both quickly and space efficiently. I created an implementation of a suffix tree in order to make the processing fast, but the ...
1
vote
0answers
11 views
Universal nested get/set for trees in Python
Based on this source, I've made the following universal get / set function, to make it possible to work on OrderedDict trees for example.
...
2
votes
1answer
83 views
Constructing and maintaining a complete binary tree
Problem statement:
Create and maintain a Complete Binary Tree in C. Include the following
operations.
Insert a given key and perform inorder
Replace ALL occurrences of the given key ...
2
votes
1answer
25 views
Decision tree for binary classification
I want to become a good Python programmer and so I'd like to know what in my code practices I can improve. Overall I feel like a pretty solid programmer but writing this code felt very "Java" so I am ...
1
vote
0answers
33 views
HDD Based AVL Tree
For class I have to write a program that reads (plaintext) numbers from a file, and inserts them into an AVL tree stored in another (binary) file. I cannot have more than about 10 nodes in memory at ...
2
votes
1answer
42 views
Path from the root to a given node in binary tree
Based on the solution provided in this question , I have written non-recursive Java code to find the path form to a given element in a binary tree. This code is working for all the elements except ...
6
votes
1answer
48 views
Prefix trees for auto suggest
I wrote a quick prefix tree implementation. I know it may be far from perfect, but I need to make sure that I got the basics right.
My main concerns are:
Have I settled for the correct data ...
0
votes
2answers
81 views
Using recursion to count nodes in a binary tree, test equality of linked lists, and find extrema of a linked list
I am working with a some small functions to test recursion. I am fairly new to Python and am wondering if there is a cleaner way to get the job done.
...
5
votes
3answers
92 views
Check if a binary tree is balanced
Looking for code-review, optimizations and best practices. This question is attributed to geeksforgeeks.
NOTE: Please help me verify space complexity, as I am creating ...
2
votes
0answers
40 views
Kruskal's algorithm in Java - follow-up
The previous and initial iteration at Kruskal's algorithm in Java
Now what I did is remove the fields and let the actual Kruskal-routine create the required data structures in the local scope, ...
1
vote
0answers
22 views
Traversing trees with Lenses
I've recently started learning about lenses and for practice, I wrote a function that finds all paths from the root to a leaf of a tree for which the total of the nodes' weights is equal to a given ...
5
votes
3answers
147 views
Tree structure with support for inorder and preorder traversal
I am learning Tree Data Structures and came up with this code for implementing basic Tree Node using class and performing various Tree based operations like Traversals and others. The code works ...
2
votes
1answer
83 views
Mathematical expression evaluator and equation solver
I'm trying to implement a mathematical expression evaluator and equation solver, and based on extensive online research and my own experimentation have come to the conclusion that the best way of ...
3
votes
3answers
294 views
Convert an array to a binary tree
I wrote this code in C++ to convert an array to a binary tree.
For instance, int nums[] = {7,5,9,1,7,3} to a binary tree (root-7, root's left child-5, root's right ...
3
votes
2answers
54 views
Searching for nodes in a huge tree
This is supposed to search for a node in a huge Treeview. The node could be found in many places. In other words there may be many nodes and the resulting tree should be expanded depending on where ...
2
votes
2answers
170 views
PrettyPrint a Binary Tree (Follow Up)
I have improved the Pretty Printing of binary tree that I implemented previously. In this follow up I have made changes such that every tree is printed (not just a Complete binary tree).
Here is my ...
5
votes
3answers
222 views
PrettyPrint a Binary Tree
I was going through this tutorial for Pretty Printing a binary search tree and decided to implement my own version. Here is my implementation. This version works only for trees that are complete ...
5
votes
4answers
410 views
Recursive Java Red-Black Tree
I've made an attempt at a recursive Red-Black tree in Java. I realise that some of my code could be condensed but I tried to favour readability with this code as Red-Black trees can be somewhat ...
0
votes
1answer
55 views
Least common ancestor in a binary tree
I saw this implementation of Least common ancestor and thought that it was very inefficient as it used Queues. I have tried to implement it using a normal tree ...
1
vote
2answers
76 views
3
votes
1answer
67 views
Least common ancestor (LCA) in a binary tree
Find the LCA in binary tree, where a node is also its own ancestor.
This question is attributed to GeeksForGeeks. I'm looking for code review, optimizations and best practices.
...
4
votes
2answers
79 views
“Functionalizing” this tree walking method and cleaning it up
I have a MessageTree class that represents a binary tree of negative/positive. I'm looking to improve my walkTree method and ...
7
votes
4answers
494 views
Recursive binary search tree - follow-up
This is a follow-up to
Recursive binary search tree
changes:
Used raw pointers rather than std::unique_ptr
const correctness
Made variable names more beautiful
implemented at()
How can I improve ...
4
votes
3answers
507 views
Preorder, inorder, postorder for tree in C++11
Please review my code for preorder, inorder and postorder of a tree. I am using C++11 (or wanted to use), so let me know if anything is deviating from the C++11 standard.
...
2
votes
1answer
130 views
Binomial heap in Java
I have this implementation of a binomial heap providing insert, decrease-key and extract in logarithmic time.
MinPriorityQueue.java:
...
3
votes
1answer
37 views
Walking and comparing contents of binary trees
I've written a solution for http://tour.golang.org/concurrency/8, which asks for a Walk() function to traverse a randomly generated binary tree, and a ...
4
votes
3answers
495 views
Recursive binary search tree
How is my usage of std::unique_ptr() and std::move()? How can I improve this code?
...
1
vote
3answers
280 views
Tree parent and child nodes
I have this method that returns true if attribute is already used and false otherwise:
...
2
votes
0answers
27 views
Basic Binary Tree in Go
As an exercise I have written a basic binary tree implementation in Go.
Tree struct:
...
7
votes
2answers
204 views
Kruskal's algorithm in Java
I have this Java implementation of Kruskal's algorithm. It solves a tiny problem instance correctly, yet I am not quite sure, whether my implementation is correct.
The code as follows:
...
1
vote
2answers
46 views
Parse a tree & return the various paths
Input:
{ 1: [2,3], 2:[4], 3: [5,6], 4:[6] }
Expected output:
[[1, 2, 4, 6], [1, 3, 5], [1, 3, 6]]
My Code:
...
2
votes
2answers
88 views
Find the size and depth of a tree
I have tried to implement two methods, one for finding the size of the tree and the other for finding the height of the tree. Can they be optimized further?
...
5
votes
1answer
135 views
Find all the paths of tree that add to a input value
This code is attributed to Stack Overflow itself here. The path which adds to the sum, which need not be starting from the root, not be ending at the leaf, i.e. a path can be between root and a leaf.
...
3
votes
1answer
87 views
Convert binary tree to doubly linked list
The code works and I get the results I want. Please comment about complexity, a shorter way of implementing the solution, and advice for better unit tests.
...
5
votes
1answer
69 views
Create a tree recursivly
I want to create a Treeview in C# which will group file by prefix (here the prefix is a marked by the separator _). The following files should give this tree:
...
6
votes
2answers
115 views
3
votes
0answers
33 views
2 4 tree insert function
I'm after creating an insert function for a 2 4 tree in Haskell. I'm just wondering if this is the best way to implement it (especially when handling the Root4s), ...
3
votes
1answer
99 views
Deepest node in tree
I have written two classes, one to represent the tree and a Util class to get the deepest node from the tree. Can you please review the code?
Below is the class ...
5
votes
2answers
119 views
Hash Binary Tree Map
I made a map based on a binary tree ordered by hashcodes, with collisions fixed with equals(). Are there any improvements I could make?
...
5
votes
1answer
72 views
Simplifying a class template
I wrote this code over night for a little project that my friend and I have been working on. This class template was created over a year ago during as a class assignment for C++ programming. I ...
4
votes
3answers
396 views
Design of a N-ary tree
A friend of mine and I recently started a project and at this moment we are writing a common library. He began writing an N-ary three and he is convinced that he has the best design with which I am ...
10
votes
1answer
108 views
Matrix to Tree Algorithm
The code takes a matrix and turns it into a tree of all the possible combinations. It then "maps" the tree by setting the value of the ending nodes to the total distance of the nodes from beginning ...
3
votes
1answer
63 views
Managing tree nodes
I have complex logic manage EnvDTE.Project and EnvDTE.ProjectItem for a VS Addin (VS 2010).
I would like elegant, easily maintainable code that follows DRY and KISS principles. Maybe using helper ...
3
votes
2answers
465 views
Better way to find the maximum value in a Binary Tree
I have to find the maximum value in a binary tree. This is how I did it iteratively:
...
2
votes
1answer
57 views
Construct the tree from a list of edges
I was using the following code to construct the tree from a list of nodes: [1, 2] means that there is a bi-directional link between ...
3
votes
2answers
197 views
Binary Search Tree in C++
I'm writing C++ for the first time and wanted to implement a BST. I come from writing C, so I tend to write code in that way. I'm trying to wrap my head around smart pointers, but can't seem to get ...
3
votes
3answers
271 views
AVL tree for inserting and searching
I have made an AVL tree. It works and does what it needs to do. I only need it to insert and search. I am comparing how long it takes to load and search a dictionary file in relation to other various ...