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
117 views

Binary Tree Longest Consecutive Sequence

I written code to solve this problem which I found on leetcode. My solution worked for the vast majority of the test cases run against it but failed on 2 for some reason. The first test case it failed ...
4
votes
2answers
109 views

Macro to convert an indented hierarchy to a database format

Our business intelligence suite outputs data as an indented hierarchy, as below: ...
1
vote
1answer
217 views

BST implementation in Python

I was asked to perform the following tasks at one of the technical interviews. I did the BST implementation in python. I think the solution passed all of the solution. I broke down the tasks in the ...
3
votes
1answer
172 views

Multi-threaded tree search

This is my first nontrivial multi-threaded program. It recursively searches through a tree (haystack) to find the leaf where ...
5
votes
1answer
698 views

Traversing the parent-child relationship between objects

I wrote this code because I was often annoyed that I couldn't get the parent object. This class allows you to traverse the parent-child relationship between objects, in both directions. It also ...
0
votes
1answer
357 views

create sorted vector of content of two binary search trees in sorted order

You are given two binary search trees, the goal is produce a sorted array of elements containing elements from both the trees. I wanted to know if there is a simpler approach, and if the use of ...
2
votes
3answers
2k views

Insertion of a node in M-way search tree

I am currently studying data structures and i am looking to see if my implementation of the insertion method in an M-way search tree is good and i am looking forward to improving my coding approach. ...
4
votes
2answers
1k views

Generic Binary Tree

I am a mathematician attempting to become proficient with C++. At the moment I am learning about data structures. I am now writing a binary tree data structure using linked list from scratch. This ...
3
votes
0answers
81 views

Binary Search Tree in Python 3

I just implemented binary search tree as described in Cormen's algorithm book. I'm not interested in correctness or performance of the implementation. I'm looking for reviews, comments on code style ...
2
votes
1answer
530 views

B-Tree implementation in secondary-memory/disk-memory

I will start by saying this implementation was based on the approach taken with B-Trees in the book: Introduction to Algorithms, 3rd Edition - Cormen, 2011 The implementation stores all the b-tree ...
3
votes
2answers
126 views

Binary Tree max sum conditionally

Problem : A binary tree is given as an input, each node of binary tree contains one integer value. Find the maximum sum of collection of nodes such that following two conditions are met. if node's ...
5
votes
2answers
306 views

Better generic binary search tree in C++

Introduction This is a follow-up to my previous question. This code rocks new ground-up implementation of core functionality, which I made from combining @vnp’s and @JDługosz's answers. The core ...
1
vote
2answers
613 views

Find all root to leaf paths in binary tree

Description: Given a binary tree, return all root-to-leaf paths. Leetcode ...
2
votes
1answer
839 views

Find all k-sum paths in a binary tree

Description: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given sum. Note: A leaf is a node with no children. Leetcode Code: ...
2
votes
1answer
328 views

Find minimum depth in a binary tree

Description: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node ...
2
votes
0answers
106 views

Python multiprocessing for tasks depending on each other

I have a simulation that runs a process on a tree structure, where the slow processes down processes are separate from each other. This looked like a thing that would be a prime candidate for ...
1
vote
1answer
207 views

Looping through a tree to get branch or leaf

This is my solution to a problem from MIT's 6.034 Artificial Intelligence course (see the heading Tree reference on 6.034 Artificial Intelligence, Lab 0). Can you please help me improve my solution (...
3
votes
1answer
123 views

Purely functional brodal heap implementation

I implemented the Brodal heap from Brodal & Osaki 1996: Optimal Purely Functional Priority Queues in haskell. The paper gives an implementation in ML but without higher-kinded types. The goal was ...
2
votes
1answer
120 views

Minimum Sum Path of Pyramid with Data Structures

I have a program that uses ArrayLists to store a pyramid that has been read by a txt file and calculates the minimum sum value of travelling from the top of the pyramid to the bottom. My code's main ...
6
votes
2answers
1k views

Generic in order traversal iterator for binary trees

This actually started off as member type for the binary_search_tree, but after realizing that it doesn't compare to values or use the value objects inside of it, I ...
8
votes
2answers
899 views

Generic binary search tree in C++

Introduction This is yet another data structure I'm going over again for the algorithms course. This time it is binary search tree. Implemented operations: Insert Exists Remove Clear Move ...
4
votes
0answers
2k views

Compression/decompression using Huffman Coding Algorithm

I am writing a program that compresses and decompresses data using the Huffman Coding algorithm. About compression: this program will export 2 files: header file (contains characters' frequency for ...
1
vote
1answer
46 views

Overloading Java function (insert into binary tree)

I have a binary tree below and it seems to make sense to overload the insert() method. If insert() is called without a ...
6
votes
3answers
1k views

Recursive Quadtree implementation in C++

I've been working on a recursive quadtree in C++. How can I improve my code? My primary goals are improving the performance/speed, as well as practice. QuadTree.h ...
0
votes
1answer
565 views

Balanced tree in C#

Given the adjacency list to represent a tree from the root (node 0) to the leaves, I want to write a function that takes this adjacency list as a parameter and return whether the tree is balanced. ...
2
votes
1answer
104 views

Implementing Complete Tree by Layers

I implement a complete tree as a layer for adding a hash, heap, and other things on top of it. The Complete_tree_node templates can be reused regardless of the number of layers added to the tree. ...
3
votes
1answer
354 views

AVL-Tree Implementation in Java

I'm looking for feedback on this AVL tree implementation. Particularly on the overall structure, readability and abstraction. I've tried to keep all AVL specific operations inside the ...
1
vote
1answer
1k views

Recursive Binary Tree Inorder Traversal in Python

This is a very simple problem to see if my understanding of basic Python is correct Problem: Given a binary tree, return the inorder traversal of its nodes' values. Example: Input: [1,null,2,3] ...
5
votes
0answers
41 views

Macao, a General Game Playing AI library - Game state goes in, best move comes out

I'm working on a simple General Game Playing AI library. The idea is that it should work with almost any kind of game, with a minimum of configuration. At the moment, I have it working on 2 player ...
2
votes
3answers
992 views

Binary search tree in Python

Create a binary search tree representation of a given array of integers. How can I improve this code? ...
2
votes
2answers
96 views

Binary tree implemented using references

I implemented a binary tree using references because I couldn't see why people don't use references instead of pointers to implement data structures such as binary trees: ...
1
vote
2answers
6k views

A general tree data structure in Java

Introduction I have this general tree data structure that imposes no restrictions on its topology: Any non-leaf node may have as many immediate children as desired. Also, there is no restrictions on ...
9
votes
2answers
4k views

Binary Search Tree Data Structure Implementation in C++11 using Smart Pointers

This implementation is part of my open source project forest. I wrote the following header file to implement a binary search tree data structure that supports the following operations: Insert Search ...
5
votes
1answer
218 views

Inserting into a binary expression tree with GOTO

I'm working on a binary space partition tree. For the time being, the nodes are only inserted into the right. A node that has children will have 0 as data. Here are the insertion rules. If the ...
4
votes
0answers
1k views

Implementation of binary search tree

I require a code review in terms of correctness, style consistency, efficiency, code readability, and "pythonic"ness. ...
6
votes
4answers
2k views

Spell-checking application in C++

This is my current coursework for university where I am to write a spell checking application and compile using C++11. I have a dictionary file that is read into the program automatically and stored ...
3
votes
0answers
761 views

Red-black tree in Rust

Although I have done a few toy projects in Rust, I haven't really done anything related to tedious memory management tasks. So I set out to create a database with the help of the project 500 lines or ...
4
votes
1answer
849 views

Max Sum of Nodes in Each Path in Binary Tree

I wanted to get a review on an algorithm I wrote for a binary tree problem. The problem is the following. Return the maximum sum between all branches in a binary tree. A branch is defined as all ...
1
vote
1answer
518 views

AVL Tree Implementation in C#

I'm new to C# so any input would be very helpful. The implementation is about as lazy as you can get and still be log n; it's more about learning how this kind of thing is done properly in C#. ...
6
votes
2answers
577 views

Nearest Neighbor Algorithm (general nearest, forward-nearest, or backward-nearest)

I am trying to write an algorithm that can find user-specified nearest neighbors. By user-specified, I mean that the user can specify whether it's a general nearest neighbor, a forward-nearest ...
1
vote
1answer
92 views

Print all nodes at k distance from the root in a binary tree iteratively

I am solving this interesting coding challenge of printing all nodes at K distance from the root of a binary tree in a iterative fashion Will be great to get review regarding how this code can be ...
1
vote
2answers
85 views

Search Tree in C

I started working on an implementation for a BST, just for myself to have some C projects. this is what I've done so far. tree.h ...
6
votes
1answer
1k views

2-3 Tree in Python

I could not find a textbook implementation of a 2-3 tree in python, so I decided I will try to do mine. ...
4
votes
1answer
1k views

Deleting a node from Binary Tree in OCaml

I am currently exploring OCaml and wrote the following implementation of deleting a node from a binary tree ...
2
votes
0answers
152 views

CIS 194 - UPenn Haskell Course (2013) - Homework 4 - Tree Folding

I have been self studying the UPenn Haskell course, and I am unable to get feedback/grading on the assignments complete. This specific portion that I am having concerns with asks to write a function <...
0
votes
1answer
396 views

generate parent nodes from leaf nodes (child nodes array) in a hierarchical tree structure

I have an array of leaf node (child nodes) and I want to find the parent nodes to them. I have a tree of approx 44000 nodes. the leaf node array for this example is ...
0
votes
1answer
12k views

Create a hierarchical tree for a JSON response

There are approx 43.000 documents (unique nodes). Building a tree structure which has 4 levels. example of 4 different levels: 13000000 - segment 13010000 - main group 13010100 - group 13010101 - ...
1
vote
0answers
230 views

Binary Search Tree find_successor of inputNode

Wanted to ask for feedback for my coding challenge for BST. python find_successor of inputNode inOrder. https://www.geeksforgeeks.org/inorder-successor-in-binary-search-tree/ find the successor(...
1
vote
2answers
314 views

Ukkonen's algorithm in C++

Here below is an implementation of the Ukkoken's algorithm in C++. Please review for correctness, robustness and performance. ...
2
votes
1answer
889 views

Binary Search Tree Implementation in Java

Looking for critiques on my BST implementation, particularly to check if I'm building the common operational methods and traversal algorithms properly. Code has been lightly tested, and I've tried to ...

1 2 3
4
5
17