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.
1
vote
0answers
7 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
127 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 ...
3
votes
2answers
72 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.
...
4
votes
3answers
103 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
100 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
551 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 ...
3
votes
0answers
22 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
30 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
89 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
71 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
72 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 ...
3
votes
0answers
43 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
60 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
81 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
98 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
57 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
76 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
56 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
94 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
31 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
90 views
2
votes
2answers
191 views
8
votes
3answers
206 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 ...
1
vote
1answer
58 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
24 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
84 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
159 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
89 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
75 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
86 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
71 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
273 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
110 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
86 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 ...
1
vote
1answer
58 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
1k 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
83 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
32 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
93 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
236 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
123 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
19 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.
...
3
votes
2answers
149 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
65 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 ...
4
votes
1answer
85 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
70 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
118 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
354 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
241 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 ...