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.
3
votes
3answers
167 views
Find all nodes in tree, without a sibling
Find all nodes of trees, without siblings.
This question is attributed to GeeksForGeeks.
I'm looking for code reviews, optimizations and best practices.
...
0
votes
0answers
25 views
Find K distant nodes
Find all nodes, which are at a distance of k from the input node.
Input:
target = pointer to node with data 8.
...
3
votes
1answer
32 views
Construct KD-Tree in Java
I want to construct KD-Tree from unsorted List of points in the plane (i.e. 2-KD-Tree). To do so I used the method from Wikipedia: http://en.wikipedia.org/wiki/Kd-tree#Construction This is my code:
...
6
votes
2answers
219 views
Binary Search Tree implementation using templates
I wrote this implementation using templates. It works fine and as expected. Just want to know if this can be improved. I have some specific questions too at the end. Please feel free to critique to ...
8
votes
4answers
303 views
Do I need Generics for these node and tree classes?
I want to implement KD tree. I have defined class Node as follows:
...
-2
votes
1answer
63 views
Given a BST, transform it into greater sum tree
Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node. Diagram is here.
Looking for code review, optimizations and best practices.
...
0
votes
0answers
10 views
Kd Tree Algorithm not working properly [closed]
I am implementing Kd Tree in 3D space where I get a point cloud and I need to store it in a kdTree structure. My problem is that it doesn't work as it should, it add the same numbers as in an infinite ...
6
votes
2answers
92 views
Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree
Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree.
Given tree:
...
0
votes
0answers
29 views
Detect if a tree is complete binary tree
Detect if tree is complete binary tree. This question is improvement over previously asked here. Looking for code-review, optimizations and best practices.
Verifying both space and time complexity to ...
2
votes
1answer
23 views
Folding with trees
I was trying to implement a foldTree function to generate a balanced binary tree from a list of values using foldr (Question 2 ...
1
vote
1answer
36 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...
...
4
votes
1answer
63 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
64 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
38 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
80 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
170 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
515 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
129 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
48 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
427 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
113 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
140 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
134 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
352 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
70 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
95 views
1
vote
1answer
69 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
180 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
273 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
295 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
161 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
70 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
113 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
44 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
222 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
361 views
Binary Tree Level Order Traversal Algoritm
I am trying to solve this Binary tree lever order traversal
...
4
votes
1answer
114 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
71 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
363 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
102 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
102 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
177 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
58 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
118 views
Binary tree/knowledge base design
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
292 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
122 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
59 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:
...