Questions tagged [binary-search-tree]
The binary-search-tree tag has no usage guidance.
38
questions
1
vote
3
answers
127
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 ...
2
votes
1
answer
80
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 ...
4
votes
2
answers
113
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 ...
-2
votes
1
answer
56
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 ...
1
vote
0
answers
60
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 ...
2
votes
2
answers
125
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:
<...
6
votes
2
answers
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 ...
7
votes
1
answer
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 ...
3
votes
1
answer
40
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 ...
4
votes
1
answer
157
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 ...
4
votes
2
answers
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+...
2
votes
2
answers
1k
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 ...
2
votes
0
answers
612
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
vote
3
answers
183
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
1
answer
356
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
...