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.
4
votes
1answer
41 views
Count number of nodes in a binary tree the OO way
Description:
I am trying to write a simplify the algorithm of finding the number of nodes
in a Binary Tree by using good object oriented design. I have been into good
OOP style recently and ...
0
votes
1answer
39 views
Root to leaf path with given sum in binary tree
For a given binary tree and a sum, I have written the following function to check whether there is a root to leaf path in that tree with the given sum.
...
3
votes
0answers
35 views
Optimising insert operation for btree
I'm working on implementation insert operation for a btree, and would like to know if there is any way to optimise the inserting operation to make it go faster. The code seems really long so I'm ...
3
votes
1answer
46 views
Trie Tree match string containing ? and *
Using Python 2.7 and here is my code which implement trie match for a whole word, and also support if the whole word contains ? (match any one character) or ...
8
votes
3answers
342 views
Building a minimal-height BST from a monotonically increasingly ordered array structure
Problem statement:
Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height.
Assumptions:
The array (and ...
2
votes
0answers
44 views
GSS4 - Segment Tree implementation 2
The problem is also known as GSS4. The exact detail can be seen here but I reached TLE.
You are given a sequence A of N(N <= 100,000) positive integers. There
sum will be less than \$10^{18}\$...
4
votes
3answers
167 views
Kattis Challenge - Animal Classification
I'm new to competitive programming and C++ in general. I have solved the Kattis Animal Classification challenge. We are given two classification trees, each represented using nested parentheses. ...
5
votes
4answers
87 views
Find the 1st and 2nd largest num in an array, O(log N) + O(N) version
I have implemented the O(logN) + O(N) version for the problem: How to find 1st and 2nd largest element in a non-negtive unique array? The algorithm principle is from this stackoverflow answer.The ...
3
votes
1answer
40 views
Printing the hierarchical representation, and finding all ascendants for a node, in a self-referential table in Python with recursion
I have a self referential database table:
CREATE TABLE category (
id INT PRIMARY KEY,
name VARCHAR,
parent_id INT REFERENCES category (id)
);
And ...
-1
votes
1answer
51 views
Diameter of a binary tree in Java
I wrote this to calculate the diameter of a binary tree. Are there any cases for which this code might fail?
...
1
vote
0answers
35 views
Finding Duplicate Subtree in O(n) time
I wrote the following algorithm to try to find the largest duplicate subtree in a tree as described here: http://ayushcshah.github.io/algorithm/binarytree/2016/04/01/detect-duplicate-subtrees.html (I ...
1
vote
0answers
33 views
Node map builder for trees
I've been building a tree from a flat collection recently in this question (Re)Creating a tree from a flat collection (or “unflatten” a tree).
It turned out very soon that this wasn't enough because ...
10
votes
1answer
208 views
Yet another minimax tree for TicTacToe
I have written a working minimax tree for Tic-Tac-Toe. What I have done so far is create a tree with end node having value 10, 0 or -10 base on win, lose or draw. After I create a tree I then ...
1
vote
3answers
92 views
Sort a list of objects to put parents first
I have a class which contains a reference to a parent of the same type( or null if it has no parent).
...
2
votes
0answers
32 views
Simple Unbalanced KDTree with 1NN Implementation
This is our first attempt at building an unbalanced k-dimensional tree with nearest neighbor (1NN) lookup to process multi-dimensional data. In particular, the "suspect region" in the ...
0
votes
0answers
40 views
0
votes
1answer
53 views
5
votes
2answers
93 views
Creating a minimax tree recursively
I am currently working on creating a tree (this is my learning process of creating a minimax tree and am starting towards minimax tree from here) with multiple nodes recursively.
Can anyone please ...
3
votes
3answers
169 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
66 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
59 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 ...
2
votes
0answers
52 views
HashMap with binary search tree for chaining
My friend was asked to implement a hashtable with a binary search tree. I tried practicing it myself, and it turned out to be very verbose. I need suggestions to clean this up!
...
0
votes
0answers
23 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
100 views
1
vote
2answers
61 views
2
votes
2answers
51 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
94 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
164 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
115 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
653 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
63 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
43 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
427 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
94 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
40 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
85 views
AVL Tree implementation in C++
I'm looking for a general review of this AVL tree implementation:
...
2
votes
0answers
39 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
63 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
50 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
65 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
144 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
143 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
37 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
366 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
176 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
62 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
109 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
72 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 ...
1
vote
3answers
107 views
RadixSet - a growing-only radix/patricia tree
I'm looking for a structure to store large amounts of strings (5k to 100k) and then test for existence of new strings against the previous inserted data, in the least possible amount of time (memory ...
2
votes
1answer
63 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 ...