21
votes
Accepted
Extraction of value from a dict-tree, given a path of arbitrary length
Recursive Approach Review
In this method you are performing too many look-ups.
First, you are looking up the 0th value of p two or three times. List indexing ...
12
votes
Extraction of value from a dict-tree, given a path of arbitrary length
Use a library.
In particular, glom does an admirable job of this, and is actively developed.
...
11
votes
Accepted
Recursive search on Node Tree with Linq and Queue
Reading Material
.. any reading material about searching algorithms on trees
These are the most common tree walkers:
Breadth-First Search
Depth-First Search
Review
There is a bug with IsRoot. Also,...
11
votes
Accepted
Using smart pointers to construct Binary Search Tree
Answers to your questions
Am I using std::unique_ptr correctly here? Using std::move and get?
Yes, you are using those correctly.
Is there any way for me to make my ...
11
votes
Accepted
Simple tree dictionary structure in C
Hide the implementation:
Node should be an opaque data type defined in the source file. The header file would then only contain the forward declaration, and the ...
10
votes
Accepted
Use generator to do inorder traversal
Your structure seems adequate, but there are a couple of mistakes, and some new language syntax in 3.3 that will make things even clearer:
That name!
...
10
votes
Accepted
Binary Search Tree Data Structure Implementation in C++11 using Smart Pointers
I would put the node inside the tree as a private member.
...
10
votes
Accepted
Generic Binary Tree
Use std::unique_ptr!
I see two potential memory leaks in the code, and both of them would have been prevented by using ...
10
votes
Accepted
Implementing a binary tree in C++ using "std::unique_ptr"
On raw and smart pointers
First, I'll address your specific question, about using a raw pointer to refer to nodes in the tree. I believe you're doing exactly the right thing here, because smart ...
10
votes
Accepted
Iterator for traversing a tree [v2]
My problem with this iterator is that it is very expensive to copy; as you have to copy a stack when you copy the iterator.
The main point of iterator is that it should be "cheap" to make copies. All ...
9
votes
Binary Search Tree BFS iteratively
Much of the code looks good. Some comments could be clearer, and there are some correctness issues.
In is_leaf(), please strike this redundant remark:
...
9
votes
Iterator for traversing a tree [v2]
Martin York already has a very good point about the iterator, so I'll not comment on that.
Avoid writing types twice
In main.cpp you are writing statements like:
...
9
votes
Accepted
Leetcode: Largest Number
Let's pretend that the purpose of LeetCode is to train for the real world. In the real world,
you wouldn't call this class Solution;
you would want to write your ...
8
votes
Accepted
Deleting a node from Binary Tree in OCaml
Syntax
There are no hard rules on this, but I would change a couple things in your syntax:
avoid ' in identifiers. Especially in that case, you can use ...
8
votes
Accepted
Iterator for BFS binary tree traversal
I'll ignore the 'PluralSight' code.
Note that you have implemented a breadth-first traversal. As far as I'm concerned, a spec which doesn't specify how the tree is traversed is insufficient, but you ...
8
votes
An array with \$O(\log\ n)\$ time complexity for all operations
Import
import java.util.*;
The class does not need to import the whole java.util package. Instead it only needs:
...
7
votes
Accepted
Red Black Tree Implementation in Kotlin
Simplification
You don't need two separate variables for REDness and BLACKness. You can just have one boolean variable ...
7
votes
Ukkonen's algorithm in C++
A couple of notes about idiomatic code writing.
Checking that a pointer isn't null before deleting it is needlessly verbose. If the parameter of the delete ...
7
votes
Accepted
Leetcode 102: Binary tree level-order traversal in Swift
Simplifying your code
Let's start here:
...
7
votes
Implementing a binary tree in C++ using "std::unique_ptr"
Here are some ideas to help you improve your program.
Fix the bug
If we create a Tree<std::string> t and then insert "epsilon", "gamma", &...
7
votes
Find the common ancestor between two nodes of a tree
Code readability and style
Your code has nothing wrong with style (as far as I know). It seems to be (99.9999...%) PEP 8 compliant.
I ran a PEP 8 checker over your code and this is what it picked ...
7
votes
Accepted
Binary Search Tree Using Templates in C++
Make it explicit that it is a binary tree
Your class name is Tree, but there are many different types of trees. Make it clear that this is a binary tree, and name ...
7
votes
Accepted
Port Node and TreeBuilder from Python to C++
Initial usage
This is not C++ like. You are using dynamic allocation where it is not needed. Simply make things local variables. Also use the constructor to make sure the objects are correctly ...
7
votes
Accepted
Optimizing a node search method given a 2-D spatial point
flags
I appreciate the clarity of this, thank you.
found = True
return cout_index, found
That is, I know exactly what the return ...
6
votes
Building a Tree from a flat List<Nodes>
Review
Keep in mind I am using an older version of .NET so my semantics can be somehow verbose.
Navigation
You are lacking a reference back to the parent, which makes bottom-up navigation much ...
6
votes
2-3 Tree in Python
My impressions on reading the question:
I bet there's a WikiPedia article on 2-3 trees. But OP gave no link. :(
No doc block describing 2-3 trees
No invariant
Lots of, as you say, "case work" encoded ...
6
votes
Accepted
Better generic binary search tree in C++
Memory management
clear and deep_copy might overflow the callstack for large number of nodes if the tree is highly unbalanced.
...
6
votes
Accepted
Binary search tree in C++, and display, search and delete functions
Overview
Your biggest issue is encapsulation (there is none).
Start writing classes with methods.
Only allow the class methods to modify the internal members.
I would note that ...
6
votes
Huffman tree compressing/decompressing in C
Header size
256*4 bytes is very big for a header. The size could be reduced substantially by using one or several of these common techniques:
Store the code length instead of symbol frequency. These ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
tree × 889java × 275
algorithm × 213
c++ × 175
python × 157
performance × 87
c# × 72
recursion × 68
c × 54
programming-challenge × 52
binary-search × 51
python-3.x × 48
javascript × 47
beginner × 45
c++11 × 43
interview-questions × 32
haskell × 27
depth-first-search × 26
breadth-first-search × 25
object-oriented × 23
python-2.x × 21
graph × 17
search × 16
array × 15
linked-list × 14