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.

learn more… | top users | synonyms

1
vote
1answer
34 views

How am I supposed to write a binary tree (S-Expression) pretty printer in C?

OK, I feel like I am doing something really wrong here. I'm just trying to create a binary tree, and a pretty printer for it. My approach is looking so bad I can't even... ...
2
votes
1answer
35 views

Detect a complete binary tree

Detect if a tree is complete binary tree or not. Looking for code review, optimizations and best practices. ...
4
votes
1answer
54 views

Segment tree implementation

I'm learning segment trees and their implementation. For the purpose, I tried solving the problem on CodeChef. Full code here My tree implementation is as follows: ...
2
votes
1answer
36 views

Basic binary Tree in JavaScript

I wrote a basic binary tree in JS. Can anyone give me some feedback about my code? I just want to know if this is the right approach, and how I can improve the tree. I am new to JavaScript and data ...
1
vote
1answer
68 views

Convert sorted linkedlist into balanced binary search tree

Convert a sorted linkedlist into a balanced binary search tree. Looking for code-review, optimizations, and best practices. ...
5
votes
2answers
138 views

Missing level of technical depth (Flatten Tree)

I recently have given a coding test in a reputable IT company. There were three coding questions. They refused me by saying that as we felt they didn't demonstrate the level of technical depth ...
7
votes
5answers
511 views

Treap implementation in C

I was needed a SET-like data structure written in pure C for some university class, so I've implemented a simple one - the Treap (or cartesian tree). Please check if everything is okay (actually, I'm ...
5
votes
2answers
116 views

Print binary search tree by levels function implementation

I do not like this implementation as is seems too much complicated. My idea was to implement some BFS algorithm variant. Some points to notice: I use one queue. In the begining put the tree ...
3
votes
0answers
43 views

Morris inorder traversal

Morris Inorder traversal - an algorithm for in-order traversal, of a tree, without recursion of extra memory. Looking for code review, optimizations and best practices. ...
6
votes
4answers
364 views

Basic Postfix Calculator in Java

I recently posted some sample code that I was providing students with and got great feedback so figured I post another one of the examples I will be providing students with. (See Simple Example of an ...
4
votes
1answer
106 views

Google Code Jam 2014: Full Binary Tree

Here is my entry for the Code Jam problem Full Binary Tree (I didn't compete but tackled the problem afterwards). It does solve the provided inputs, so I suppose it is correct. I am looking for any ...
3
votes
2answers
131 views

BinarySearch Tree implementation & traversals

I am practicing various tree algorithms and that require code review for it's efficiency, clarity and also if it can be made better etc. Is there a better way to call ...
6
votes
5answers
132 views

Initializing JTree

I have a class called Piece, and many many subclasses of Piece. I want to add an instance of every single subclass of ...
11
votes
1answer
292 views

Recursion vs iteration of tree structure

Some recursive code is part of a particularly slow path of a project. Out of curiosity I was playing around with reimplementing the code using stack context iteration instead of recursion. Below are ...
5
votes
1answer
67 views

Tree implementation for unordered keys

The following is an implementation of a tree in C++ designed for keys which do not have an order (otherwise a std::map could be used). ...
5
votes
1answer
93 views

Segment tree in Python3

I've implemented a Segment Tree in Python3: ...
1
vote
1answer
66 views

Print left view of the tree

Left view of a Binary Tree is set of nodes visible when tree is visited from left side. Left view of following tree is 12, 10, 25. ...
8
votes
2answers
149 views

Tree Template Class Implementation for C++

I have not done any parameter checking, however I think the meat of the class is there. Let me know what you think. ...
3
votes
1answer
237 views

Expression tree creation from postfix expression

Given a postfix expression, construct an expression tree. Looking code code review, optimizations and best practices. ...
5
votes
4answers
248 views

Find the sum along root-to-leaf paths of a tree

Most of you already know me, please be brutal, and treat this code as if it was written at a top tech interview company. Question: Given a binary tree and a sum, find all root-to-leaf paths where ...
11
votes
2answers
154 views

Free a binary tree without using recursion or allocating memory

As the title says, the objective is to free a binary tree without using the stack or allocating memory. This was required for a kernel module where resources were limited. Result has a complexity of ...
5
votes
1answer
65 views

Interface for a tree node in Qt

I have the following C++ interface (in Qt) for a tree node, inspired somewhat by Valve's implementation of a culling octree: ...
1
vote
3answers
109 views

Preorder traversal of binary tree to produce formatted string

Given a complete binary tree returns the following format (Parent ( leftchild (leftchild, rightchild), rightchild(leftchild,rightchild) ). Looking for code review, optimizations and best practices. ...
2
votes
1answer
41 views

Isomorphic trees verification

Two trees are called isomorphic if one of them can be obtained from other by a series of flips, i.e. by swapping left and right children of a number of nodes. Any number of nodes at any level can have ...
6
votes
2answers
214 views

Class for printing class hierarchy as text

I'm coding a little class hierarchy printing tool for easy show hierarchies of java classes. This is my current code: ...
4
votes
1answer
306 views

Binary Tree Level Order Traversal Algoritm

I am trying to solve this Binary tree lever order traversal ...
4
votes
1answer
107 views

Correctly implementing the Swing TreeModel

Ideally the Code Review would target the correctness of the approach implementing the Swing TreeModel. In particular, is the structural separation[1], event message passing, threading[2], object ...
-1
votes
2answers
64 views

QuadTree can't handle many elements

I'm currently implementing my own QuadTree in C++. It runs well with 100 items, but once you start adding more it slows down. remove, ...
7
votes
2answers
362 views

Determine quadrant of code

I'm currently in the process of coding a QuadTree. The QuadTree seperates into four quadrants, with 1 being the top right and 4 being the bottom right. I have this code to determine which quadrant ...
6
votes
2answers
59 views

Alternate way for comparison call back function?

I'm doing a programming practice problem and was wondering if someone can suggest a better to create/setup the call back for the comparison function. I have the following classes: ...
6
votes
1answer
98 views

Functional, but not recursive, tree traversal

To learn tree traversal i implemented os.walk, tail-recursive and stack-based. Unfortunately Python doesn't support tail call optimization. How do i rewrite my ...
10
votes
1answer
101 views

Binary Tree/ Amorphous Binary Tree Creator

I suppose this is a two-part question. The first part is just a simple implementation of a Binary Tree (BTree), with pre-order, post-order, and in-order searches ...
6
votes
1answer
167 views

How can this python quadtree be improved?

Here's an attempt I've made of implementing the Barnes-Hut nbody algorithm, or its initial stage - The quadtree. That there're lots of lengthy doc strings might excuse the lack of detailed explanation ...
1
vote
1answer
54 views

Transform a MongoDb parent reference tree into a deep nested tree

Given a mongodb collection that stores trees as nodes with parent references this methods returns a deep nested tree where every child nodes are stored in a property childs[Seq] ...
5
votes
2answers
102 views

Binary Tree/Knowledge Base design C++

Currently I have a binary tree template setup where my main is using it with strings to make a question/answer game. I'm using a knowledge base that works as an interface to the binary tree that main ...
2
votes
1answer
266 views

Printing the values on each level of a Binary Tree

The below code is for printing level-by-level in a binary tree: ...
5
votes
3answers
2k views
2
votes
1answer
118 views

Level-traverse a binary tree

Level traverse binary tree question: Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary ...
2
votes
2answers
58 views
3
votes
1answer
73 views

Reading messages with binary tree

I'm building a binary tree. Example: key AAAA1.ETR, value 1. I'm reading files with this structure: ...
2
votes
2answers
103 views

Algorithms for traversing unordered tree

I have been doing some programming 'exercises'. I'm trying to come up with the most efficient algorithm for tree traversal. Consider the following function signature: ...
1
vote
3answers
258 views

Lowest common ancestor in recursive tree traversal

LCA = Lowest Common Ancestor The following code finds the lowest common ancestor in tree of nodes, where a node can have two parents, left and right. The tree looks like this: ...
4
votes
2answers
337 views

Interval search tree

An interval is a data structure that represents a range (start & end, from & to, or min & max, etc.). An Interval Tree stores these intervals in a sorted tree structure that makes ...
3
votes
1answer
74 views

Join/ connect all levels of Binary tree without any aux storage

This program connects all nodes of the binary tree at the same level. A node of a tree contains a left, right and a sibling pointer which would connect it to the next node at the same level. This ...
2
votes
1answer
58 views

Iterator for binary tree - pre, in, and post order iterators

Implemented iterator for a binary tree and "pre" "in" and "post" order flavors. I'm looking for code review, best practices, optimizations etc. ...
5
votes
1answer
82 views

Hide the tree menu at a certain depth

I have created this piece of js purely for learning purposes and I was hoping you could code review to see any mistakes / improvements I can make. Basically I have a tree structure and I will use the ...
1
vote
1answer
320 views

Search an element/item in an n-ary tree

Search an element in a n-ary tree. Looking for good code practices, optimizations etc. If question is ambiguous, let me know and I will reply ASAP. Note - ...
4
votes
2answers
94 views

Testing to see if tree is BST

I found a function online that tests if a tree is a binary search tree: ...
3
votes
1answer
123 views

Inorder traversal of a tree without recursion or stack

Please review the code for code cleanup, smart optimizations and best practices. Also verify my complexity: O(n2), where n is the number of nodes ...
5
votes
1answer
72 views

Unbalanced binary search tree

I wrote this unbalanced binary tree and would like to know how to improve the code and performance. If you can point out any situations that are not being handled appropriately, that would be great ...