Questions tagged [tree]

A tree is a graph in which there is exactly one path between any two nodes. It is often used as a hierarchical data structure.

Filter by
Sorted by
Tagged with
0
votes
1answer
232 views

At least 2 paths down the binary tree have the same sum

Problem statement Write a function that given a binary tree, returns true if at least 2 paths down the tree have the same sum. A path is a series of nodes from the root to the leaf. Examples: ...
6
votes
0answers
289 views

C - fully threaded binary search trees

For learning purposes, I've decided to implement several classic data structures, starting with binary search trees. The entire code can be seen here, in a frozen branch ...
3
votes
1answer
93 views

Leetcode Count of Smaller Numbers After Self solution

Question link You are given an integer array nums and you have to return a new counts array. The ...
1
vote
0answers
39 views

Benchmarking TreeSet in Java against a van Emde Boas tree based integer set

VanEmdeBoasTreeIntegerSet.java ...
2
votes
1answer
3k views

Recursive BFS solution for tree traversal

I'm somewhat new to the wonderful world of Python, outside of simple codecademy-like challenges online. This function was part of a project for school. It's tested and works, but I'm looking for some ...
4
votes
2answers
2k views

Binary Tree in C

It takes integers from argv[] and inserts into tree, making sure to allocate memory and free that memory once the program has finished. How can I improve code quality, what are your suggestions? <...
1
vote
1answer
110 views

Building tree from edges puzzle with performance requirement

I'm working on a puzzle and have solved it, but my code is not fast enough to get the maximum score (if the code is faster than a certain achievable threshold, one gets awarded the maximum score). I ...
5
votes
3answers
1k views

Binary Search Tree BFS iteratively

I was given this coding question for a technical interview: Given a binary tree, implement a method to populate the list level_ordered_list with the data of the nodes traversed level-order, ...
2
votes
0answers
303 views

BinaryTree traversed in postorder (DFS), iteratively

I was given this coding question for a technical interview: Given a binary tree, implement a method to populate the list post_ordered_list with the data of the nodes traversed in postorder, ...
1
vote
1answer
32 views

Searching for a binary tree for a vehicle with a given name

I'm searching my binary search tree of Vehicle objects and I'm just wondering whether there would be much point, if it's best practice to search to see if a node ...
2
votes
1answer
148 views

Object oriented design for a Tree

I am implementing a Tree in Java. It must be easy to add a new type of tree e.g. Binary tree and Tertiary tree. Each node can have at least one value. It must be easy to make a new type of node and ...
3
votes
1answer
815 views

Binary search tree in C++ 17 using iterator pattern

I am new to C++ and am attempting to write the following binary search tree using the iterator pattern (and std::optional in C++17): ...
1
vote
1answer
81 views

Binary search large tree in C

I tested creating 1 billion (1,000,000,000) nodes and lookups are fast. You can ask for a node by node_id. ...
1
vote
2answers
115 views

Binary Tree Maximum Turns

Given any binary tree, what is the maximum number of turns possible in any path from root to any leaf? A turn is when the path involves moving from left branch to right or vice-versa; i.e. the number ...
1
vote
0answers
356 views

Python AVL Implementation

I wanted to get an understanding of different data structures and therefore implemented an AVL tree in Python. I hope that some of you might be willing to check it for correctness. The binary tree ...
1
vote
1answer
83 views

Walk on tree with different actions on different nodes

I have a tree whose nodes are of type Node. Depending on the type (one of the implementations of Node) nodes differ in the set ...
4
votes
2answers
2k views

Loop for inserting a node into a binary search tree

I am trying to implement binary search tree. One method which I am trying to implement in the most efficient and stylish way is node insertion. I am under the impression that while (true) is a bad ...
4
votes
1answer
270 views

Checking if two binary trees are identical

Two binary trees are considered equal if they are structurally identical and the nodes have the same value. Tree is defined as : ...
2
votes
1answer
1k views

Given a binary tree, find the maximum path sum

This is a leetcode.com problem. For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The path must ...
4
votes
1answer
2k views

Generic Binary Search Tree class written in C#

...
4
votes
1answer
467 views

Red Black Tree Implementation in Kotlin

I know that there are enough Red Black Tree implementations in the Java libraries, like e.g. java.util.TreeMap. Yet I wanted to create my own for learning purposes ...
1
vote
0answers
171 views

Radix trie optimization

I have got a list of Users that I want to filter using text typed in TextView. I want it to be a smart filter, something like searching contacts in contact book on ...
0
votes
1answer
2k views

Tree Implementation in Java

We are implementing a Tree structure and came up with two possible Tree Implementations. Implementation-1 is a straight forward class while Implmentation-2 uses a nested Static Class. My Question ...
3
votes
2answers
711 views

Algorithm that generate all possible strings from N Tuples. Found Brute Force version, Recursive Version uses a Tree?

I am trying to figure out a solution for a problem. Consider the following tuples (it could be any number of tuples, I am using four in this example): {A, B, C, D}...
5
votes
2answers
2k views

Binary Search Tree in C++

I have written this code for Binary Search tree. Help me to improve this code using C++11 and C++14. Where to use functions like minimum() ...
3
votes
2answers
926 views

Binary Search Tree Implementation (practice)

Note: I do know that Python libraries provide Binary Search Tree. This implementation has been done to practice python, and <...
6
votes
2answers
2k views

Python Binary Search Tree

As an exercise to get better in Python, I decided to implement a Binary Search Tree. This implementation uses two classes: BSTNode and BSTree. Because most methods were implemented using recursion, I ...
1
vote
0answers
419 views

Deletion of Word from Ternary Search Tree where Both Siblings Present

This code review will require somewhat a more indepth look at the code operation (at least it did for me) to understand the two word deletion areas and the node rotation and frees I'm most concerned ...
0
votes
1answer
1k views

Generating and finding parent nodes in a post-order tree

Given a height h and list q of integers, list the parent node of each element in q, if nodes are read in post-order sequence ...
2
votes
1answer
557 views

Binary search tree implementation in golang

I have started dabbling with golang. I wrote up a binary search tree implementation. I was wondering if there is a cleaner way. Here is my implementation: ...
5
votes
3answers
1k views

Python Binary Search Tree Implementation

...
1
vote
1answer
611 views

Count number of leaves in binary tree

Description: Given a binary tree find the number of leaves. Although the problem is simple and has been solved many times I am more interested in find object oriented ways to solve the algorithmic ...
3
votes
2answers
760 views

C++ binary search tree, not using recursion

I made binary search tree using classes. I would like to know if I could do something better or maybe there is something wrong with my code. I decided not to use recursion. I would be very thankful ...
12
votes
1answer
3k views

2D Bin Packing Algorithm Implementation

I wrote a 2D greedy bin packing algorithm using Python 3.6 Heres a quick summary: The algorithm consists of two classes (which I will attach at the end of this file along with a link to my github ...
2
votes
1answer
51 views

inroder_iterator for syntax tree of markargs

Introduction It is a spin-off to my compiler creation. Problem Traverse the markargs::syntax_tree in order, e.g. first goes ...
6
votes
2answers
795 views

HackerRank Binary search tree validation

From here: ...
5
votes
1answer
2k views

Coding Decision Trees in VBA

I have created a function in VBA as follows: ...
0
votes
1answer
85 views

Creating a nested treeview Rails

I have a dataset that looks something like this: ...
5
votes
1answer
245 views

Draw a directory tree

My goal was to create a simple-to-use CLI program for drawing directory trees (what tree does on most platforms, basically). I'm submitting my 'backend' program for ...
3
votes
2answers
617 views

C - Generic Binary Search Tree

I'm a novice C programmer (moving onto C++ soon) and I've tried to implement a basic (search,insertion,deletion) generic unbalanced BST whilst adhering to a few OO design principles. I'm looking for ...
1
vote
0answers
170 views

SPOJ GSS1 challenge (maximum subarray sum) using Java

The problem is presented here as follows: You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defined as follows: Query(x,y) = Max { a[i]+a[i+1]+...+...
2
votes
1answer
598 views

Tree containing different data types [closed]

For a while I was thinking of a way I could have multiple objects of different types that related to each other be included in a tree. For example, say I have CEO, Manager, Representative which all ...
1
vote
1answer
937 views

RB Tree Left and Right Rotate Functions

I am writing a program to implement the Red-Black Tree data structure in java. Below is the beginning of my implementation, namely the left and right rotate functions. I want to know if these ...
2
votes
2answers
2k views

Splitting Hashmap by converting to TreeMap

I have a project requirement where I have to split a HashMap of around 60-70 entries into multiple HashMaps. The critical number of the split is 30 due to ...
2
votes
1answer
107 views

Time complexity of common ancestor algorithm

I have an algorithm here to find the common ancestor of two nodes in a binary tree. ...
2
votes
1answer
1k views

Checking if a tree is balanced

I'm trying to implement balanced tree checking by python like following. ...
8
votes
1answer
831 views

A small Java library for neat printing of binary trees to text console

Given a binary tree (not necessarily a binary search tree), this small Java library implements an algorithm that can neatly print binary trees to text console. Code BinaryTreeNode.java ...
3
votes
1answer
264 views

“The Story of a Tree” solved using depth-first search

Found this problem in hackerrank. One day Bob drew a tree, with \$n\$ nodes and \$n-1\$ edges on a piece of paper. He soon discovered that parent of a node depends on the root of the tree. The ...
3
votes
1answer
439 views

KQuery SPOJ problem, using merge sort segment tree

Problem : KQUERY Summary: For each query consisting of \$(i, j, k)\$, return the number of elements greater than \$k\$ in the subsequence \$a_i, a_{i+1}, …, a_j\$. My code has complexity of \$O(n\...
7
votes
1answer
446 views

Counting nodes in a binary tree with odd values, using an iterative algorithm

I've to simulate exactly a recursive algorithm with an iterative one. Assuming that I have a binary search tree that contains only a key and two references at his right and left child I want to do ...