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
13 views
2
votes
1answer
24 views
0
votes
0answers
28 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
49 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
32 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
57 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
118 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
87 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
35 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
331 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
126 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
59 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
99 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.
...
0
votes
0answers
7 views
Binary Tree Paths - what is wrong with my code [migrated]
Here is the binary tree paths problem:
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
...
2
votes
1answer
47 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
60 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
77 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
64 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
71 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
517 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
389 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
76 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
50 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
29 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
53 views
1
vote
1answer
42 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
46 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
57 views
3
votes
3answers
218 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 ...
2
votes
0answers
50 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
0answers
62 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
28 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
92 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.
...
1
vote
2answers
88 views
Summing all keys in the leaves of a tree
My program takes 35 sec to run example 2. How can I make my program faster?
...
0
votes
1answer
60 views
Common ancestor in a binary tree
This method finds the common ancestor of two nodes in a binary tree.
Any style suggestions or ways to make it more idiomatic? Is the algorithm correct? Rubocop says the cyclomatic complexity is too ...
1
vote
1answer
103 views
A basic pure Python hash map using a tree
I would like feedback on my first attempt to understand how hash tables work. I've read some on how hash tables use modulo operations to find the location of a key.
Can you help me understand, ...
5
votes
0answers
72 views
B+ Tree Visualization in LaTeX/TikZ
I have written a LaTeX package to visualize B+ trees.
The main purpose is to provide a simple but powerful package which provides a convenient interface.
However, this is my first LaTeX package and ...
1
vote
2answers
69 views
Next node of a node in Binary search tree
To find the node next to a given node we need to consider two cases.
case 1: if the node has a right subtree then return the min node in its right subtree.
case 2: if the node doesn't have a right ...
0
votes
1answer
50 views
Create a binary search tree from a sorted array (increasing order)
Description:
Since the input array is sorted, we can take the middle element of the array to be parent and recursively do the same on the left and right halves to create left and right sub trees of ...
0
votes
1answer
42 views
Create D lists of nodes where D is the depth of the binary tree
I have used a HashMap of ArrayLists to maintain the nodes at each depth.
Also i maintained a depth at each node in the binary tree by using a HashMap that stores . While traversing the tree in a ...
3
votes
2answers
67 views
Simple Octree implementation
I've implemented a rather straightforward octree, but I don't feel that good about the coding style or some of the implementation. In particular, I use some nasty ...
0
votes
0answers
57 views
AVL Tree Array Representation
In a school assignment I'm supposed to create a program simulate insertion, deletion, count nodes, and delete tree algorithm and displays the traversal, level order, and array representation of it. ...
4
votes
1answer
52 views
Classification tree in Swift
As an effort to teach myself Swift as well as to get familiar with machine learning algorithms, I've been trying to implement common algorithms, starting with a Random Forest. This is, for the moment ...
1
vote
3answers
201 views
Priority Queue (Binary Search Tree) Implementation
I have made a Priority Queue implemented as a Binary Search Tree. I would appreciate comments related to optimization and proper functionality, but any comments/critiques are welcome.
PQ.h:
...
6
votes
1answer
712 views
Breadth-first search on a tree in Python
The following code performs breadth first search on a mockup tree
...
1
vote
1answer
98 views
Find pairs in binary search tree in which sum of nodes keys is equal key
There is a task:
Given a binary search tree of \$n\$ nodes, find all the pair of nodes whose sum is equal to a given number \$k\$ in \$O(n)\$ time and constant space.
Please let me know if you ...
2
votes
1answer
59 views
Counting the number of increasing sub-sequences
The problem is to find the number of increasing sub-sequence of a string with only digit characters.
Answer may be very large, so output it modulo 10^9+7.
I have been able to get a O(n) solution ...
3
votes
1answer
68 views
Design of tree data structure
I am practicing for technical interviews and I am encountering a lot of problems relating to the tree data structure. I have gone through other posts that discuss about the tree data structure and ...