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.
2
votes
0answers
27 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
224 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
87 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
109 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
108 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
165 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
59 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
74 views
1
vote
1answer
44 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.
...
7
votes
2answers
82 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
132 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
149 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 ...
9
votes
1answer
104 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 ...
2
votes
0answers
33 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
82 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
36 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
170 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
100 views
Binary Tree Level Order Traversal Algoritm
I am trying to solve this Binary tree lever order traversal
...
4
votes
1answer
60 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
54 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
357 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
52 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
80 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
75 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
127 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
42 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
85 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
134 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
1k views
1
vote
0answers
84 views
level traverse a binary tree
Level traverse binary tree question
The problem is pretty common level order traverse a binary tree but break each level into single array.
I implemented mine: I've designed a few test cases, but ...
2
votes
2answers
47 views
3
votes
1answer
69 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
78 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
227 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
230 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
69 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
44 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
70 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
248 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
84 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
92 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
60 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 ...
6
votes
1answer
326 views
MutationObserver (shim): Finding differences between 2 DOM trees
I've been working on a MutationObserver es5 shim and would appreciate some feedback on my technique for identifying changes between a ...
0
votes
1answer
716 views
Serializing/deserializing binary tree in most space-efficient way
I'm looking for corrections, optimizations, general code review, etc.
...
1
vote
0answers
124 views
Review my F# Red Black Tree Implementation [closed]
I have written this implementation for red black tree. I also have some helper methods to verify whether the generated tree is really balanced or not.
Looks good to me.... but I find that most of the ...
3
votes
2answers
96 views
Constructing a binary tree in java
I am constructing a binary tree. Let me know if this is a right way to do it. If not please tell me how to?? I could not find a proper link where constructing a general binary tree has been coded. ...
1
vote
1answer
122 views
Max depth of tree when all parent pointers are provided
Request for optimization, good practices, recommendations.
...
4
votes
1answer
366 views
Printing a Binary Tree top-down (column wise)
We have a binary tree, suppose like this:
8
/ \
6 10
/ \ / \
4 7 9 12
/ \
3 5
We have to print this binary tree in top-down ...
5
votes
1answer
2k views
Prims algorithm implementation
Review this code regarding optimization, cleanup, and best practices.
...
5
votes
1answer
95 views