Skip to main content

Questions tagged [binary-tree]

Filter by
Sorted by
Tagged with
5 votes
5 answers
1k views

I implemented a recursive solution that compares the left and right subtree in mirrored fashion. It works for my test cases, but I would like to know if there are any best practices that would make ...
Jared McCarthy's user avatar
2 votes
2 answers
704 views

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 ...
Slav's user avatar
  • 121
2 votes
3 answers
178 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
108 views

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 ...
coderodde's user avatar
  • 32.3k
2 votes
1 answer
117 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
5 votes
2 answers
266 views

Its been done to death, but the particular prompt (see Assignment 4) guiding me has strict+simple requirements that lead to a nice reduced environment to critique poor form. The project implements a ...
shea's user avatar
  • 153
4 votes
2 answers
155 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
5 votes
1 answer
134 views

Given a binary search tree, the problem requires calculating the minimum absolute difference between any two keys in the tree. Given the binary search property, the minimum difference must be between ...
loonatick's user avatar
  • 153
3 votes
3 answers
994 views

I'm playing around with a toy implementation of binary trees in C. I have a typedef'd struct BTree like so — ...
ZarakshR's user avatar
  • 145
15 votes
5 answers
4k views

I have tried to implement my Heap in C. The following are the 13 operations defined: build_maxheap insert exctract_max (delete heap max root) max_delete (delete an element or key) max_heapify clear ...
V_head's user avatar
  • 575
2 votes
1 answer
127 views

I've written a program that uses a binary tree to essentially 'learn' about animals given the name and questions about them. Learn is probably a little strong of a word, all it does is store the ...
ravenclaw900's user avatar
1 vote
1 answer
195 views

So I have this binary spaced partition leaf: ...
Aspect11's user avatar
  • 135
3 votes
2 answers
337 views

My code for a Binary Expression Tree that takes postfix input from the user and recursively builds and evaluates the expression. Proper input can be assumed. ...
MadHatter's user avatar
  • 865
2 votes
1 answer
195 views

I am trying to solve the lowest common ancestor problem in Rust. It is guaranteed that the id's of the tree are unique. It is also guaranteed that the two nodes which we are looking for in the tree ...
Agnishom Chattopadhyay's user avatar
4 votes
1 answer
3k views

I have an assignment due Friday to make a family tree. Started to code in January. My reviews from the teacher for this code was that the use of pointers was horrendous and it wasn't OOP enough. This ...
Shayeza's user avatar
  • 43
3 votes
1 answer
645 views

I wrote a simple huffman coding algorithm for learning and practice. I just used the technique given on the wikipedia page. Could you tell me my missing points and mistakes? Node.java ...
gedofgont's user avatar
2 votes
2 answers
285 views

This is my first attempt at writing a library in C. I have only included tree creation and in-order traversal function for now, but will expand to have more functions soon. I have three files, ...
Vedant Jadhav's user avatar
2 votes
1 answer
200 views

I have the following solution to this problem. The idea is to compute the maximum width of a binary search tree. The width of a BST on a particular depth is defined as the distance from the leftmost ...
coderodde's user avatar
  • 32.3k
1 vote
1 answer
164 views

I have used a queue, which has been implemented using a singly linked list, to facilitate the level-wise creation and traversal of the binary tree. ...
Kushagr Jaiswal's user avatar
2 votes
1 answer
246 views

I am trying to determine the correctness of a helper method within my MaxHeap class. The goal of this helper method is, given the index of any node in the Max Heap, sink it to the correct level in the ...
MPC's user avatar
  • 61
2 votes
1 answer
144 views

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 ...
beatmaister's user avatar
1 vote
1 answer
175 views

I've implemented a map using a Patricia tree, using u64 as keys. I would like general feedback on my code, but I have one thing that I think could be implemented in ...
Tyilo's user avatar
  • 605
2 votes
0 answers
130 views

A while back, I answered this question on Stack Overflow that involved deserializing a binary tree breadth-first using functional programming (the question itself isn't relevant). I'd like to make ...
user's user avatar
  • 539
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
161 views

I've added some methods to a basic BST implementation for integers - if anyone can point out some ways that this could be written in a more efficient or clean manner, please let me know. ...
SomeoneLearning17's user avatar
2 votes
1 answer
218 views

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 ...
curious's user avatar
  • 333
1 vote
2 answers
231 views

I am trying to resolve following problem. Please advice which part of the code can be improved. Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the ...
Erdenebat Ulziisaikhan's user avatar
2 votes
2 answers
231 views

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. <...
Saurabh's user avatar
  • 445
2 votes
1 answer
170 views

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 ...
Enlico's user avatar
  • 531
5 votes
0 answers
207 views

I was wondering if we could speed-up lookup in a hash table of strings by only storing the difference between them, like HAMT. Taking this idea to its end, I ended up with a binary PATRICiA prefix-...
Neil's user avatar
  • 1,112
1 vote
1 answer
227 views

To sum up all the nodes' depths in any given binary tree, I've written the following recursive algorithm: ...
thehorsetrack2001's user avatar
5 votes
1 answer
164 views

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? ...
Anonymous's user avatar
  • 1,244
0 votes
1 answer
446 views

I've been trying to kind of teach myself "Modern C++" the last couple of months and I just finished this interview type problem and thought it would be a good one to get some feedback on. I not ...
Brandon Moretz's user avatar
1 vote
2 answers
313 views

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 ...
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
3 votes
2 answers
392 views

Given a binary tree, return the sum of values of its deepest leaves. Constraints: The number of nodes in the tree is between 1 and 10^4. The value of nodes is between 1 and 100. Please ...
Gilad's user avatar
  • 5,443
3 votes
1 answer
70 views

I implement BinaryTree (K extends Comparable, V) concept to binarySearchTree and I have written get and put method. As far as I check, there is no problem in my code. So now I wonder that are there ...
Samir Allahverdi's user avatar
1 vote
2 answers
3k views

I just created a BinarySeachTree class in c++ which is supposed to store words read from a txt and the number of occurances of those words and i would just like some feedback from you. I think it ...
Kritsos's user avatar
  • 13
2 votes
1 answer
2k views

I am trying to implement DSs in C++ and this is BST insert and search functions. I tried in two different ways, please review and see if one is advantageous over other. With pointer to pointer ...
Nothing_8484's user avatar
3 votes
2 answers
1k views

I am trying to learn to implement DSs in C++ and here is a simple implementation. Please review in terms of optimization, memory management, coding standards, etc ...
Nothing_8484's user avatar
3 votes
1 answer
198 views

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 ...
user_185051's user avatar
3 votes
1 answer
398 views

My solution to the LeetCode's Subtree of Another Tree passes all the test cases, but the code feels and looks ugly. Would appreciate an advice on how to improve it. The problem: Given two non-empty ...
user_185051's user avatar
4 votes
0 answers
108 views

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 ...
Sarabjot Singh's user avatar