# Questions tagged [binary-search-tree]

The tag has no usage guidance.

38 questions
Filter by
Sorted by
Tagged with
1 vote
106 views

### Maximum Sum BST in a Binary Tree

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 ...
69 views

### Sort array of numbers using tree sort - Leetcode 912

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 ...
• 123
111 views

### Delete a node in binary tree

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 ...
• 121
55 views

### Market Portfolio Binary Search Tree [closed]

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 ...
• 212
1 vote
57 views

### Binary Search Tree Universe

In the world of Binary Search Tree (BST) enthusiasts, where collecting and trading BSTs is a craze, you have a beloved BST with n nodes. In this scenario: (a) Identifying Swapped Nodes and Common ...
• 212
97 views

### Binary search tree with Iterators

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: <...
• 107
1k views

### Avoiding memory leaks and using pointers the right way in my binary search tree implementation - C++

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 ...
1k views

### Pet Shelter in C++

The provided code represents an implementation of a Binary Search Tree (BST) in C++, specifically tailored for a "Pet ...
39 views

### Convert sorted list to BST

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 ...
152 views

### Binary Search Tree implementation in C [1]

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 ...
• 525
152 views

### Max Stack implementation in C++ involving iterators

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+...
959 views

### C# Binary Search Tree implementation

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 ...
564 views

### C++: STL-like AVL Tree (+ benchmark vs. my red-black tree and std::set)

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 ...
• 1,703
1 vote
178 views

### Binary Search Tree that allows for duplicate elements - C++

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 ...
1 vote
333 views

### Binary Search Tree implementation in C++ with templates

Im implementing a BST using templates and dynamic memory, here is my attempt: This is the BSTNode.hh ...
• 269
53 views

### Simple non balancing indexed binary search tree

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+...
• 21
608 views

### Binary Search Tree - My own version of delete function

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 ...
738 views

### Maximum Depth of Binary Tree in JavaScript

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. ...
• 3,993
1 vote
101 views

### Binary Search tree, leaves method [closed]

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 ...
587 views

### red black tree implementation in cpp

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) ...
452 views

### c++ Most clean way to implement duplicate Binary Search Tree for complex type

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 ...
840 views

### Binary Search Tree in C++ without parent pointers

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 ...
• 217
2k views

### BST implementation in rust

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 ...
• 163
125 views

### Finding inorder successor of a BST in C [closed]

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 ...
105 views

### AVL Tree in C Criticism

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 ...
• 419
1 vote
147 views

### Binary Search Tree without pass by reference

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, ...
• 205
200 views

### LeetCode 173: Binary Search Tree Iterator

The original problem statement is here, here is the super short summary: Your binary search tree iterator must implement the following interface: ...
• 315
73 views

### Validate Search Binary Tree [closed]

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 ...
• 105
1k views

### AVL Tree in C++

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 ...
1k views

### Using smart pointers to construct Binary Search Tree

I have three main questions: Am I using std::unique_ptr correctly here? Using std::move and ...
• 375
93 views

### STL compatible Binary Search Tree with unique_ptr (unit test included)

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 ...
• 131
2k views

### Red-Black Tree Implementation in Python

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. <...
1 vote
427 views

### Implementing a binary search tree using std::unique_ptr

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 ...
83 views

### BST implementation (MIT OCW Runway scheduling problem) + Unit Testing in Python3

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 ...
146 views

### Binary Search Tree (BST) Implementation

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....
• 1,224
404 views

### BST implementation using smart pointers in C++

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 ...
• 313
465 views

### C word frequency counter

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 ...
• 864