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 ...
8
votes
Accepted
AVL Tree in C++
About inheritance
I would advice against using (public) inheritance of BST for AvlTree. Consider that with your code, the ...
8
votes
Reservation app in C with linked list, BST, and CSV
This is an interactive, menu-driven program. I would expect that runtime failures would result in a return to the menu. But instead, we unceremoniously dump the user back to their shell without ...
8
votes
Reservation app in C with linked list, BST, and CSV
UX
When I run the code, I see this message:
loadCSV: No such file or directory
The code expects me to have a file named "res.csv", but I do not.
The ...
8
votes
Implementation of a balanced binary tree
Some notes.
Indentation
I would strongly suggest four spaces rather than two for each level of indentation. With such minimal indentation, your code is a bit hard to follow.
You may get value out of ...
7
votes
Accepted
Pet Shelter in C++
Things you would not do in real code
I know you have been given some restrictions, however in code you write outside of a course you would not have these restrictions and you would do things ...
6
votes
Avoiding memory leaks and using pointers the right way in my binary search tree implementation - C++
Given you are not using any actual C++ functionality, I’m going to think about this code as C code that uses new and delete ...
6
votes
Accepted
Reservation app in C with linked list, BST, and CSV
General linked list suggestions
You are treating Node ** as (the head or tail of) a list. This means that insertion at the opposite end must traverse the entire ...
5
votes
Accepted
Binary Search Tree implementation in C [1]
Fix compilation warnings
If your compiler isn't telling you about these, you haven't enabled enough warnings:
BST* create_bst(void) {
/*🔺🔺🔺*/
<...
4
votes
Accepted
BST implementation in rust
This looks good for a first project. Most of the review to follow ranges from debatable to nitpicky.
Representation
It's unusual that BST can't represent an empty ...
4
votes
red black tree implementation in cpp
This ia a great follow-up and deserves a closer look than I can give it right now, but a handful of things jumped out at me.
Write the Class as a Template
You’ve got a nice tree class, but it’d be a ...
4
votes
Accepted
Binary Search Tree - My own version of delete function
Address more fundamental issues before worrying about delete
A BST should be able to hold false values. For example, zero. Instead of if not self.root, use ...
4
votes
Accepted
Sort array of numbers using tree sort - Leetcode 912
edge case
I feel the first result displayed here is reasonable:
>>> sorted([])
[]
>>> sorted([6, 4])
[4, 6]
Given zero elements, and asked to ...
4
votes
Reservation app in C with linked list, BST, and CSV
The recursive call in printListRecursive() is not needed, and could be a simple while loop:
...
3
votes
Accepted
Maximum Depth of Binary Tree in JavaScript
A few minor style suggestions for starters:
Use const instead of let. let says "I'm ...
3
votes
Accepted
Binary Search Tree in C++ without parent pointers
Move struct Node inside struct BST
A Node is just an implementation detail of a ...
3
votes
Accepted
Binary Search Tree implementation in C++ with templates
Stick with a single language
I see you have some Catalan comments, and instead of BSTTree you write BSTArbre, but all other ...
3
votes
Simple non balancing indexed binary search tree
More horizontal spacing please. Give your operators some breathing space. It is very hard to read things like root==nullptr||i<0||i>=root->size. BTW, I ...
3
votes
Simple non balancing indexed binary search tree
Use unique_ptr for root, left, and right
Because each ...
3
votes
Finding inorder successor of a BST in C
Missing return
Code may even fail the last rt == INT_MAX and then no return is specified.
...
3
votes
Validate Search Binary Tree
To validate a BST tree you need to validate a sub tree is between two values.
Remember that all nodes to the left must be less than the current node and everything to the right is larger. So after a ...
3
votes
Accepted
BST implementation using smart pointers in C++
This is too long for me to review thoroughly, but on a cursory glance (I'll just go go top to bottom):
#include <iostream> is unneeded
There is no point in ...
3
votes
Avoiding memory leaks and using pointers the right way in my binary search tree implementation - C++
For C++, avoid using new/delete or c variants of memory allocation. Instead use std::make_unique.
Fix formatting, for example, consider using ...
3
votes
Maximum Sum BST in a Binary Tree
Is there anything I can change, in the same given code, that would optimize it and/or get it accepted?
Your “Time Limit Exceeded” question is basically asking “when is this code slow?”
We tend to ...
3
votes
Maximum Sum BST in a Binary Tree
Beyond method naming and a comment stating what the signature boolean isBST(TreeNode root,…) suggest, the code gives no indication what it is there for, what the ...
3
votes
Weight balanced tree in OCaml
From a reviewer perspective I find it difficult to identify what the short variable and type names mean and thus for what they are used.
Note: I must admit that I am not familiar with the language ...
3
votes
Implementation of a balanced binary tree
Implement the interface of std::map
To make your code be a drop-in replacement for standard library containers,
try to implement the same interface for your ...
2
votes
Implementing a binary search tree using std::unique_ptr
Observation
I normally don't see a parent pointer in a binary tree.
Because you have to keep and maintain this extra pointer your code is a lot more complicated ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
binary-search-tree × 42c++ × 19
tree × 9
algorithm × 7
c × 7
python × 5
binary-tree × 5
python-3.x × 4
time-limit-exceeded × 4
pointers × 4
object-oriented × 3
programming-challenge × 3
linked-list × 3
java × 2
c# × 2
c++11 × 2
reinventing-the-wheel × 2
rust × 2
javascript × 1
performance × 1
beginner × 1
.net × 1
sorting × 1
recursion × 1
comparative-review × 1