Questions tagged [binary-tree]

The tag has no usage guidance.

21 questions
Filter by
Sorted by
Tagged with
65 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? ...
253 views

Simple Binary Search Tree Class with Insert and Search Functions

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

LeetCode: Deepest Leaves Sum C#

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. ...
158 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 ...
79 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 ...
297 views

Leetcode: Subtree of Another Tree

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-...
44 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 ...
33 views

I need to know that if everything okay in my BTS put and get method

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

Binary PATRICiA Prefix Trie

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 it's end, I ended up with a binary PATRICiA prefix-...
442 views

Simple BST implementation using C++ Struct

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 ...
65 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 ...
75 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. <...
72 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 ...
69 views

Deserialize a binary breadth-first in functional programming

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

How can I optimize this Binary Search Tree?

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

Find Binary Tree Path Sum

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

Binary Search Tree in c++ used to count words in a text

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

Best way to store the sum of all node depths?

To sum up all the nodes' depths in any given binary tree, I've written the following recursive algorithm: ...