Tagged Questions
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
2answers
136 views
3
votes
3answers
99 views
+100
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 ...
1
vote
1answer
49 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
1answer
21 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
12 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
43 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
142 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
63 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 ...
4
votes
0answers
52 views
Persistent segment tree
I'm trying to solve this problem.
Given a sequence \$B=B_0,B_1,\ldots,B_{N−1}\$
for each query \$(P,K)\$, find the minimum \$S\$
s.t. there are at least \$K\$ entries in \$B\$ that satisfies
...
7
votes
1answer
64 views
Quad Tree and Collision Detection Implementation
I have an implementation of a quad tree and abstract collision detection classes. The code works but looks very ugly, but I don't know what I could change to make it better.
The reason I used two ...
3
votes
0answers
30 views
Print the nodes of binary tree column-wise, using recursion and iteration
I am trying to code for both recursive and iterative approach to a problem.
Below is a recursive code to print the nodes of binarytree column wise. Basically I have count of root as 0 and if I move ...
2
votes
1answer
104 views
Array implementation of unbalanced binary search tree
I'm preparing for an interview. I tried implementing binary search tree in C++. I used array but it seems to be complicated to restructure the array while deleting nodes. Is linked list a better data ...
8
votes
2answers
104 views
Trees and their uses
I was getting sicker and sicker of using an ordinary collection to do a tree's work, so I built a tree. A requirement of the tree are that it needs to contain a key to sort the tree by, so I used a ...
8
votes
1answer
69 views
Growing my own Tree (Structure)
Summary
VB6 doesn't have a great selection of data structures to work with, so again I find myself creating my own. I have a need to dynamically generate a directory structure on the file system. The ...
0
votes
0answers
37 views
Rendering JSON array as a tree
This code is working fine for me, but I want to simplify it.
Function parents is defining parents of the tree and children ...
10
votes
1answer
344 views
Quadtree implementation
I've implemented a quadtree in C++. Ignore any apparent similarity to the pseudocode on Wikipedia, it's all in your head, I swear.
How can I improve? Algorithm speed/space improvements, any extra ...
5
votes
1answer
61 views
Tree list recursion from Stanford tutorial
I have found this appearing-to-be famous problem in Stanford tutorial about trees and decided to solve it.
My solution appears to work great:
...
3
votes
1answer
23 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
79 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 ...
1
vote
1answer
127 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
90 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
13 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
96 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
36 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
40 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
53 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 ...
7
votes
1answer
64 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
177 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
154 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
62 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
31 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
247 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
99 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
444 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
57 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
277 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
291 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
502 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
64 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
86 views
3
votes
1answer
76 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
85 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
530 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
681 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
214 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
38 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
580 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
363 views
Tree parent and child nodes
I have this method that returns true if attribute is already used and false otherwise:
...
2
votes
0answers
32 views
Basic Binary Tree in Go
As an exercise I have written a basic binary tree implementation in Go.
Tree struct:
...
7
votes
2answers
481 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:
...