All Questions
Tagged with binary-tree tree
12 questions
2
votes
2
answers
678
views
Binary tree deepcopy using the Morris traversal in C
I need to perform a deep copy of a binary tree using the Morris traversal.
I think I managed to do it, that is the code below returns what I expect; however, I am not 100% sure I have covered every ...
2
votes
3
answers
150
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
95
views
Semi-dynamic range minimum query (RMQ) tree in Java
Introduction
I have this semi-dynamic range minimum query (RMQ) tree in Java. It is called semi-dynamic due to the fact that it cannot be modified after it is constructed. However, the values ...
2
votes
1
answer
132
views
Find ALL duplicate subtrees. using recursion
This is just a practice exercise, I'm trying to understand dynamic programming as deeply as I can. I solved this using recursion, though I am not sure if it will always work. If anyone could tell me a ...
3
votes
1
answer
114
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 ...
2
votes
1
answer
203
views
Implementation of binary tree traversal
Based on what i understood of Binary Tree, queue and recursion I implemented this Breadth First Search algorithm as follows.
Do you have any suggestions to improve (in term of readability, good ...
2
votes
2
answers
221
views
Lowest Common Ancestor in Binary Tree (Iterative)
In the below code I've implemented a method to find the lowest common ancestor of a binary tree.
This is an iterative approach using this pseudocode.
Please suggest any improvements that can be made.
<...
2
votes
1
answer
142
views
HackerRank - Binary tree to compute the Nth power of natural numbers that sum up to X
I'm trying to solve this challenge on HackerRank.
In short, given x and n, I have to determine how many ways I can pick numbers ...
5
votes
1
answer
143
views
AVL Tree implementation Based on VisualGo
I have tried implementing an AVL Tree on my own, based on visualising it. But i'm unsure how many testcases it work with, and how efficient it is. Are there any ways to make it efficient, and compact?
...
1
vote
2
answers
286
views
Leetcode: Cousins in Binary Tree
Mu solution to Leetcode problem Cousins in Binary Tree works, but the code feels bulky. Is there a better way to solve this problem, particularly to use less additional variables? I will appreciate ...
3
votes
1
answer
186
views
LeetCode: Most Frequent Subtree Sum
My solution to LeetCode problem Most Frequent Subtree Sum works, but I have several questions regarding the code. I am also looking for an advice on how to improve the code.
Problem:
Given the ...
4
votes
0
answers
94
views
Implementation of an AVL tree using a List
Please suggest some ways to improve it. It takes input values from the user and builds a height balanced tree (AVL tree) after applying Rotation and then prints the in order traversal of the tree ...