Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.

Questions tagged [binary-search-tree]

Filter by
Sorted by
Tagged with
6 votes
2 answers
453 views

I never remember without looking how to write RB or AVL balancing. but I wanted to make sure I would be able to still write a reasonable dynamically balanced binary tree. If it is asked of me in ...
Ralender's user avatar
4 votes
1 answer
198 views

The objective was to create a weight-balanced binary search tree with a well-defined interface. Any critiques or suggestions for improvement are welcome. ...
Chris's user avatar
  • 5,462
5 votes
4 answers
780 views

This is a reservations app with linked lists for insertion and BST for search. It uses CSV files for storage, recursion for printing and handles memory allocation for variable growth. I'm looking for ...
Attila Vajda's user avatar
2 votes
1 answer
103 views

I've implemented an AA Tree (a type of self-balancing binary search tree) using Numba, a just-in-time compiler for Python. This implementation includes rank and select operations, which are useful for ...
Krosvick's user avatar
2 votes
2 answers
114 views

I'm trying to organize the code according to the run menu of a schedule using the binary tree data structure because if I search for a user, the menu always appears first, and the listed user is left ...
user avatar
2 votes
3 answers
176 views

I was trying to find the Maximum sum BST of a binary tree on LeetCode. While the Java code I have come up with, mostly seems right and is able to pass 55 out of the given 59 test cases too, the error ...
Siddharth Garg's user avatar
2 votes
1 answer
116 views

Problem statement: Sort integer array nums in O(N log N) time, without relying on any library sort routine. I am trying to use a tree sort method (using the ...
qxzsilver's user avatar
  • 123
4 votes
2 answers
151 views

Problem Statement Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST. Basically, the deletion ...
iskander's user avatar
  • 121
-2 votes
1 answer
104 views

I'm trying to solve the following problem here: First line of input contains the number of days D. The next d lines contains a character c and a number x. If c is B, then buy stock . If c is S, then ...
driver's user avatar
  • 222
2 votes
2 answers
157 views

One more BST implementation with iterators added. Did not manage to find another implementation with iterators and it is my first attempt at implementing them so thought to check on your opinion: <...
acd's user avatar
  • 107
6 votes
2 answers
2k views

I'm learning C++ and I wanted to test my knowledge by implementing a Binary Search Tree using struct (I know, I’m using C++ I should use classes but I want to keep ...
Neptune Luke's user avatar
7 votes
2 answers
1k views

The provided code represents an implementation of a Binary Search Tree (BST) in C++, specifically tailored for a "Pet ...
i_hate_F_sharp's user avatar
3 votes
1 answer
57 views

I am working on a Daily Coding Challenge to convert a sorted singly-linked list into a binary search tree. We are given the head of the list; the definitions of ...
Arya Singh's user avatar
5 votes
2 answers
240 views

I have tried to implement my Binary Search Tree in C. The following are the 18 operations defined: create a bst is_empty insert delete clear find find_min find_max height size depth level order ...
V_head's user avatar
  • 575
4 votes
2 answers
202 views

The tricky thing was keeping copies of list iterators in a tree map and managing both together. I'm not handling invalid input cases (like popping an empty stack) in this code. I am following Google C+...
user267704's user avatar
2 votes
2 answers
1k views

I have implemented a Binary Search Tree and would really appreciate it if someone could take time to check it and give me feedback. I try to keep my code clear and simple. Is it readable? Is the API ...
Kirill Dolghi's user avatar
2 votes
0 answers
852 views

AVL trees and red-black trees are most famous balanced binary search trees. I've always wondered "Why do all major C++ standard library implementations use red-black trees as their ordered ...
frozenca's user avatar
  • 1,751
1 vote
3 answers
231 views

I've recently made an attempt at creating a binary search tree class that allows for duplicate elements. I've included as many functions as I can think of so that I can use it later on. I've tested ...
0xREDACTED's user avatar
2 votes
2 answers
414 views

Im implementing a BST using templates and dynamic memory, here is my attempt: This is the BSTNode.hh ...
Norhther's user avatar
  • 279
3 votes
2 answers
80 views

The following code represents a simple indexed binary search tree of integers. The insert method inserts an int. The indexed lookup looks up the ith smallest element (0 indexed). I'm trying to write C+...
ha1234's user avatar
  • 31
4 votes
2 answers
681 views

Well, I am recently learning data structures and algorithms and I came across the Binary search tree and decided to first time use my own logic to make the delete function. I have not come across a ...
Muhammad Ahmad's user avatar
3 votes
1 answer
806 views

The task Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. ...
thadeuszlay's user avatar
  • 4,015
1 vote
1 answer
131 views

I have written a code of Binary Search tree that extends comparable and implements an interface. The code for leaves and the helper method countLeaves, makes sure that all of the test goes through ...
user17024023's user avatar
2 votes
1 answer
683 views

I am learning algorithms and trying to implement them in c++, I have chosen to try to implement a red-black tree due to its self-balancing properties and its ability to stop the worst case of O(n) ...
paigelarry342's user avatar
1 vote
2 answers
549 views

I have tried to make my own implementation for a BST task I was given for a complex type (Transaction), that should be able to store duplicate values as well. However, I am not sure if I have gone ...
paigelarry342's user avatar
3 votes
2 answers
935 views

This is one more implementation of Binary Search Tree in C++. There are many such implementations, however they are typically long and complex, and also many of them rely on pointers to parent nodes ...
HEKTO's user avatar
  • 217
6 votes
1 answer
3k views

I am looking for some feedback on my implementation of binary search tree in rust and I would appreciate someone taking the time to go through it and suggest any improvements or corrections as they ...
RoboT's user avatar
  • 163
0 votes
1 answer
167 views

Please review this code I have written a function to find the successor of BST in c. It takes three arguments, i.e root pointer to the binary search tree, node value of which we have to find a ...
Abrar Ajaz Wani's user avatar
3 votes
1 answer
133 views

I have made an AVL tree in C and coded the basic functionality of insertion, deletion, and search. I would love some criticism on my implementation especially on the insertion and deletion section of ...
CLox's user avatar
  • 419
1 vote
2 answers
165 views

Here is a code for BST that I have written , that does not use pass by reference. Help me to find flaws in its design. Also I do not like the function getReqNodes, ...
motiur's user avatar
  • 205
3 votes
0 answers
215 views

The original problem statement is here, here is the super short summary: Your binary search tree iterator must implement the following interface: ...
alisianoi's user avatar
  • 315
-2 votes
1 answer
94 views

I was looking to this exercise: Is Valid Binary Search Tree I tried to do the exercise by myself without looking to the solution and my code is "much simpler" than the code I found at the ...
a.dibacco's user avatar
  • 105
8 votes
3 answers
1k views

After not programming in c++ for some time, I decided to write an AVL tree implementation to get back in shape (I wasn't that good anyway. Still an amateur). Header File bst.hpp ...
Saleh Shamloo's user avatar
9 votes
1 answer
1k views

I have three main questions: Am I using std::unique_ptr correctly here? Using std::move and ...
gust's user avatar
  • 375
4 votes
1 answer
137 views

I am trying to create a Binary Search Tree, which has STL support (iterators etc.). This is my first attempt. Everything is unit tested using Catch2. Could you please review what I missed and what I ...
MartenBE's user avatar
  • 141
8 votes
1 answer
2k views

I'm wondering if there are better practices, and optimizations I could make on my code, to do things easier/faster. I have added comments, in many places in the code, to make understanding easier. <...
user avatar
1 vote
1 answer
457 views

I have implemented a binary search tree with 2 operations to begin with. I have tried to implement it using the best practices I could think of. Overall, I am happy with the implementation. But, I ...
Gaurav Sharma's user avatar
4 votes
1 answer
110 views

Inspired by MIT OCW (6.006)'s lecture on BSTs, I implemented them with the slight tweak where an element has to satisfy the "k-minute check" before insertion. If its value is within k of any other ...
cloudy_eclispse's user avatar
4 votes
1 answer
164 views

This is the first Time implementing a Binary Search Tree, based on how it works from the visualgo website. I made this algorithm purely based on what I saw, and the remove method was quite challenging....
Anonymous's user avatar
  • 1,244
3 votes
1 answer
435 views

This BST implementation seems to work, I would appreciate an advice on how to improve the code. I am also interested in the following: rule-of-5 methods, are all of them necessary (e.g. is destructor ...
user_185051's user avatar
3 votes
2 answers
528 views

I write this program based on the algorithm of the word frequency counter program on the K&R book, page 139. I added some idioms of mine, some command-line options, and a dynamically allocable ...
phillbush's user avatar
  • 864
2 votes
1 answer
84 views

https://leetcode.com/problems/increasing-order-search-tree/ Please review for performance Given a binary search tree, rearrange the tree in in-order so that the leftmost node in the tree is now ...
Gilad's user avatar
  • 5,443