6,396 questions
4
votes
3
answers
186
views
Efficient ways to check if two binary trees are the same
I implemented a recursive solution in Python to check if two binary trees are identical, which traverses nodes recursively and compares values and structure. The time complexity is O(n), space O(h).
...
0
votes
0
answers
36
views
How do I display my BST using my preorder() and inorder() methods?
I'm doing a programming assignment for my class. One of my programs includes creating a BST with Python within a BST class, and I'm trying to display using preorder() and inorder() functions. My ...
6
votes
2
answers
248
views
Prefer container::lower_bound to std::lower_bound?
I understand that container::lower_bound harness helpful invariant of the very container hence gives a better performance than std::lower_bound.
Taking std::set::lower_bound as an example, during my ...
1
vote
1
answer
100
views
How to implement insertion into BST iteratively in Rust?
I'm trying to implement an algorithm for insertion into BST (binary search tree) in Rust. I did it recursively, but am having problems implementing the iterative solution. I'm struggling to borrow a ...
-1
votes
1
answer
70
views
What form of recursion is occurring in the "insert "and "list_all" methods of this code?
I am struggling to understand the recursion going on in the insert, _insert_recursive and _inroder_traversal methods. For context, I know recursion and the concept is not strange to me, I struggle to ...
0
votes
1
answer
76
views
understanding a part of recursion for a binary search tree
Hello I basically need to implement a recursive function for insertion of a binary tree. I already implemented the chunk of insertion function (wether it's largest or smaller than root) but there's an ...
3
votes
1
answer
712
views
Difficulty setting up threaded BST in C++
I'm having trouble implementing a threaded Binary Search Tree in C++. I have a non-threaded tree completely implemented (see below code). What I'm having difficulty with is setting the threads to ...
0
votes
0
answers
56
views
Error When Mutably Borrowing a Value From a Struct That Has Been Mutably Borrowed
Explanation
I'm attempting to implement a binary search tree in Rust. The problem is in the insert method, where I have a &mut Box<Node<T>> called node_to_insert_at. To insert the ...
0
votes
2
answers
104
views
Binary search tree memory leak adding residual child nodes to new trees
I'm having two issues with my code; I'd post them as two separate questions, but I believe one is causing the other. The first involves insertion; from my amateur eyes, the insert code seems to be ...
2
votes
2
answers
79
views
Self-balancing binary search tree and duplicated keys
I've implemented a red-black tree (which is a kind of self-balancing binary search trees) with duplicated keys allowed. In the Insert method I put nodes with equal keys as right child nodes. As you ...
0
votes
0
answers
28
views
Optimizing frequent deletions in a BST: AVL vs. Red-Black Tree?
I am working on optimizing the Delete-Max operation in an unbalanced Binary Search Tree (BST) where frequent max deletions occur. The current approach follows:
Traverse to the rightmost node.
Remove ...
1
vote
1
answer
56
views
Maximum difference between node and its ancestor Java soltion having issue
I am practicing Maximum difference between node and its ancestor Java problem using my own solution which worked fine for smaller test cases. However, this is giving differnt output than expected for ...
2
votes
1
answer
196
views
Data structure for easily finding the maximum length of a non-decreasing sequence on a certain interval
I'm trying to find a solution for this challenge:
Given is n, which is the size of an array filled with ones. There are two types of operations possible on this array:
Increase (x, y, m): add m to ...
0
votes
1
answer
96
views
solution to factorial problem using dynamic programming resulting in more time than simple recursion
I was just starting out with dynamic programming and tried solving factorial problem using the same, i used binary tree for underlying data structure, but when i thought of comparing it with normal ...
1
vote
0
answers
37
views
Removing Root Node from a BST?
I build my tree in main with a for loop adding nodes 1-15, removing say 5 or 15 work fine, i think my problem lies in removing the root. It wont follow pre-order when I call it after removing 1, i ...