Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

4
votes
2answers
61 views

Generic tree data structure for flat data from a database

Could someone please review my code for performance(any other suggestions are welcome) which converts flat data list coming from database to a tree? Interface for db entity class ...
4
votes
1answer
45 views

Maximum depth or height of a Binary tree

The Following function is supposed to calculate the maximum depth or height of a Binary tree the number of nodes along the longest path from the root node down to the farthest leaf node. ...
0
votes
0answers
27 views

Traversing the Parent-child relationship between objects: Part 2

This code builds on the code in the previous iteration. All of the following tests should work: ...
2
votes
1answer
68 views

Monoidal tree interview in Haskell

I was working on the following interview question: Given an array of integers, return a new array such that each element at index i of the new array is the ...
2
votes
0answers
45 views

Pretty print a tree [closed]

When you're working with trees one of the most useful methods to implement is a clear way to print them, the following is my solution to print a tree in Java: ...
1
vote
2answers
46 views

Binary Search Tree delete function

I have implemented this delete function for BST. Tt takes care of all the three cases, deleting node with 0, 1, or 2 children. I have added comments throughout to explain my decisions. Is it sloppy ...
3
votes
0answers
32 views

Generating all unlabeled trees with up to n nodes

I want to visualize all unlabeled trees with \$n\$ or fewer nodes, not just count them. First idea/attempt: Take a list of all \$n-1\$ node trees, then append a new leaf to every tree in every way to ...
3
votes
1answer
53 views

Implementing a tree parsing function

I've solved an assignment a week ago, which is my first assignment using Lisp. Tasks: Task 1: a. Given a tree as recursive lists, print the tree in breadth first order. b. Given a tree like ...
3
votes
0answers
80 views

All the paths from the root to the leaves

Given a binary tree, return all root-to-leaf paths. Example: -- 1 / \ 2 3 \ 5 Output should be: ["1->2->5", "1->3"] My approach: I walk the branches ...
4
votes
1answer
49 views

ZigZag tree travesal

The question is taken for a coding interview I had, it is also in geeks for geeks, https://www.geeksforgeeks.org/zigzag-tree-traversal/ you are given a binary tree and you need to print it in a ...
0
votes
1answer
40 views

Binary search tree traversal and depth first search in Python

I am learning about the tree traversal, and I would like to ask for feedback. Using recursion, write a function that takes in a binary search tree and number of outputs a list of values ordered by ...
7
votes
2answers
181 views

Iterator for BFS binary tree traversal

I implemented an iterator pattern for C# using IEnumerator and IEnumerable. The goal of the implementation is to traverse a ...
3
votes
2answers
73 views

First Swing at an AVL Tree Implementation in C++

I've implemented a simple AVL binary search tree. For no real reason I decided to implement this without multiplicity, so if we try to insert(5) twice, it's only stored once in the tree. I've also ...
0
votes
1answer
43 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
67 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
64 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
71 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
288 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
89 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
53 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
232 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
54 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
52 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
86 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
173 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
82 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
95 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: ...
3
votes
1answer
80 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
35 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
66 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
60 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
47 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 ...
5
votes
2answers
90 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 ...
7
votes
2answers
415 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
147 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
39 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
161 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
63 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
96 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
116 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
170 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
31 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
117 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
72 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: ...
0
votes
2answers
426 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 ...
0
votes
0answers
24 views

findInOrderSuccessor in a Binary Search Tree python

I would like to ask code review for the following problem that I solved. https://www.geeksforgeeks.org/inorder-successor-in-binary-search-tree/ ...
6
votes
2answers
775 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
116 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
239 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
128 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 ...