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
0answers
20 views
3
votes
3answers
137 views
(Re)Creating a tree from a flat collection (or “unflatten” a tree)
I need to create a tree from a flat collection. The order of elements is defined in a specification so it's rather impossible that it will ever change... but I want the whole algorithm to be ...
1
vote
1answer
55 views
Print tree level by level including Empty node
Here is my code to print tree in a level by level way. It needs to print an empty node as well to keep tree structure like full binary tree for elegancy reasons.
I'm wondering if anything you think ...
2
votes
2answers
58 views
Game combo press model (substring search)
I'm trying to make a model for checking combo presses in a game. Given a list of Button (enum) presses, it returns the list of possible combos completed. I tried ...
0
votes
0answers
18 views
k-Ary Tree Implementation
Simple implementation of k-ary trees. Is this the "correct" / standard way of implementing k-ary trees?
...
3
votes
3answers
64 views
1
vote
2answers
55 views
2
votes
2answers
49 views
AVL tree insertion and deletion of nodes in C. 2.0
I asked a question yesterday, based on the answers to that question and some personal insights I was able to update the original code. which I am posting here to get reviewed. I also thought about ...
2
votes
3answers
80 views
C++ Tree Class implementation
I am trying to implement a class for the Node of a Tree in C++ in order to represent an HTML structure.
It is not complete by a shot, but i'd still like an opinion.
TreeNode.h :
...
3
votes
2answers
142 views
AVL tree insertion and deletion of nodes in C
This is my implementation of AVL tree, it works fine. is there any thing that can be improved about addition and deletion procedures specifically when deleting the root,
...
4
votes
2answers
108 views
Print tree in a zigzag manner
I want to print a tree in a zigzag manner level-by-level. I'm wondering if there are any logic issues in my code and any further performance improvement ideas by using a smarter algorithm ...
6
votes
1answer
648 views
Code smell when recursively returning a List
So this is part of my AVL tree implementation, namely the infix representation of the tree. Since I wanted to use a recursive method to stay close to the original algorithm and want to return a list, ...
1
vote
0answers
50 views
AVL Tree implementation in Rust
I'm mainly looking for tips in how make my code more idiomatic and elegant, but any general reviews are welcome.
...
4
votes
1answer
40 views
Building a nested tree structure from an ordered list
I have an ordered list in this format. The data is ordered by path so that the list will never contain a child before the parent in the list.
...
7
votes
3answers
413 views
Designing a binary tree structure from scratch in C
I'm a beginner and self learning programming students. While learning binary tree data types, for the sake of understanding graph theory and other interesting programming problems, I've writen the ...
1
vote
0answers
64 views
In-memory B+ Tree in C++
I know B+ trees are not meant to be use in memory, but I just implemented it as an exercise. I'm looking for a general review.
...
0
votes
0answers
36 views
Suffix tree code
I am always having confusion when it comes to run time complexity of an algorithm. I wrote this code for suffix array, I am not sure of the run time complexity of ...
5
votes
1answer
70 views
AVL Tree implementation in C++
I'm looking for a general review of this AVL tree implementation:
...
2
votes
0answers
38 views
LinkedList of Nodes at each level - optimalization
That's already known problem: to return an array of linked lists that contain values of elements at each level. Eg for tree with depth n there should be n linked lists.
I wrote the solution:
...
2
votes
0answers
59 views
In-memory B-Tree
I know B-Trees are meant to be used for external memory, but I implement it to understand the algorithms involved in insertion and deletion. Also, I didn't use a vector because I was asked not to use ...
3
votes
0answers
46 views
AVL Tree Implementation in Haskell
I'd like to get some feedback on my AVL tree implementation. I appreciate any comments related to style and performance, particularly if something can be written in a more concise or idiomatic way. If ...
2
votes
2answers
62 views
Finding the Least Common Ancestor of a Binary Tree
Input a binary tree (the root node) and 2 other nodes that need to be assessed for finding the least common ancestor (LCA)
Code:
a. Finding the nodes first with either ...
3
votes
2answers
131 views
A generic AVL tree with SequenceType, CollectionType and ArrayLiteralConvertible extensions
I'm learning Swift and trying get a good understanding of some of its many features. The following is an AVL tree implementation with extensions that conform to ...
6
votes
1answer
124 views
Binary Tree Implementation in Rust
To teach myself Rust, I implemented a naive binary tree with support for insert, delete and lookup operations as well as in-order iteration.
I'm still a little rusty (no pun intended) when it comes ...
2
votes
1answer
36 views
Segment tree challenge
Here is my implementation of a segment tree with a sample driver file (I didn't make an update function because I didn't need it for what I was doing).
I'm a huge fan of geeksforgeeks, but I do not ...
4
votes
2answers
347 views
Generic binary tree in C#
This is a simple implementation of a generic binary tree that holds elements of type T. I was wondering if there was something that could be done better (especially in the EnumerateNodes methods).
<...
3
votes
0answers
139 views
Data model for complex tree (multiple children and multiple parents)
I'd like to have a discussion on the data model (mostly) for a tree with nodes having multiple children and multiple parents.
I already have a working algorithm, but I'm looking for improvements.
The ...
-3
votes
1answer
60 views
Building a binary search tree and finding a node in it
I am new to Java so go easy on me, here is my code:
...
4
votes
1answer
101 views
Simple binary search tree for use in programming competitions
I made a binary search tree implementation in C++ for my personal use in programming competitions.
...
2
votes
1answer
52 views
Deletion of a node in a binary search tree
I am looking to see if my implementation of the removal/deletion method in a binary search tree is sufficient, readable, and runs in \$O(\log n)\$ time. It's been awhile since I've written a data ...
2
votes
1answer
61 views
Check binary tree symmetry by reversing, checking equality, coverage tested, makefile
A few weeks ago I recall a HackerNews story (found it again: "I Don't Want to Hire You If You Can't Reverse a Binary Tree") about reversing a binary tree (with, as I remember it, the end goal being to ...
4
votes
1answer
78 views
Managing IDs using AVL trees
In a txt file there are IDs and next to them there are their neighbours like this:
1 1
1 2
1 3
2 1
2 4
2 8
3 5
Using AVL trees I store the IDs in one AVL ...
2
votes
1answer
80 views
Mirror image of a binary tree
I wrote a small routines to create a mirror for any binary tree. I am just sharing my necessary routines instead of full class. could you please let me know your comments on this. I just curious to ...
3
votes
0answers
78 views
Zipper trees implementation
Considering the lack of general purpose library to manipulate trees (not to mention zipper ones), I may end up packaging this piece of code, so I would like it to be reviewed first.
Any comment is ...
3
votes
3answers
627 views
Finding the tree height in Python
I'm trying to get an efficient algorithm to calculate the height of a tree in Python for large datasets. The code I have works for small datasets, but takes a long time for really large ones (100,000 ...
4
votes
2answers
410 views
Inorder, Preorder, and Postorder traversal of a binary tree in C++
I am a newbie in this world of data structures and algorithms (returning to these topics after 5 long years). Can someone please check if the code I have written for Binary Tree is OK?
Test-case
10, ...
2
votes
1answer
90 views
Traversing a Binary Search Tree in Swift
I'm implementing the Binary Search Tree data structure in Swift. It looks like this:
...
5
votes
1answer
52 views
Speed concerns of octree implementation
For couple of days now I am trying to speed up my Force-Directed graph implementation. So far I've implemented Barnes-Hut algorithm that's using octree to decrease number of computations. I've tested ...
0
votes
1answer
30 views
Follow-up zp-Tree to represent Trees as nested arrays: 3rd (final?) revision
This is a follow-up on my previous post.
I have made modifications based on the feedback received on the previous post, hence I request a third (final?) review on the modified code if ok.
Note: ...
0
votes
1answer
21 views
Follow-up zp-Tree to represent Trees as nested arrays
This is a follow-up on my previous post.
I have made modifications based on the feedback received on the previous post, hence I request another review on the modified code if ok.
Note: review ...
1
vote
1answer
56 views
1
vote
1answer
46 views
zp-Tree library to represent trees as nested arrays
For my project I have rewritten a small lib for a tree structure that was inspired by wangzuo's js-tree.
The reason was largely because I prefer to work with an array structure rather than nested ...
0
votes
0answers
19 views
Lazy segment tree implementation
I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially the ...
0
votes
0answers
53 views
Segment tree implementation in C++
I wrote a C++ implementation of a segment tree (I wrote it for an arbitrary function, not "lazy" version) and I want so much to ask for a review. I'd like to know how I can make it better, especially ...
-1
votes
1answer
62 views
3
votes
3answers
230 views
Building prefix tree from dictionary, performance issues
I'm trying to build a prfix tree. So, using the following dictionary 'and','anna','ape','apple', graph should look like this:
I've tried 2 approaches: using ...
3
votes
1answer
79 views
Binary search tree class in Java
I am trying to create a binary search tree class in Java and am wondering how I did. I am fairly confident on most of the methods, but fear I may have messed up the delete method. I know I am ...
3
votes
1answer
83 views
Check if a binary tree is a binary search tree or not
This checks if both the left and right subtrees are binary search trees. If they are, then it compares the nodes data with the maximum element in the nodes' left subtree and minimum element in the ...
2
votes
1answer
29 views
Verify that a binary tree is balanced
A binary tree is balanced if both its children are balanced and the difference between the heights of its children is at most 1.
...
4
votes
1answer
101 views
Implementing Binary Tree using Queue in C#
I am in the process of learning data structures and I am trying to implement Binary Tree using Queue in C#.
Below are my Tree implementation classes.
...