Tagged Questions
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 ...
8
votes
4answers
296 views
Do I need Generics for these node and tree classes?
I want to implement KD tree. I have defined class Node as follows:
...
6
votes
4answers
411 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 ...
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 ...
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:
...
6
votes
2answers
81 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:
...
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:
...
5
votes
1answer
112 views
Duplicate detection and reporting in a BST
For the purpose of this problem, the BST is defined to allow duplicates, and the duplicate values will always follow to the right-side of the parent nodes with the same value. For example, with the ...
5
votes
4answers
285 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 ...
5
votes
1answer
2k views
Prims algorithm implementation
Review this code regarding optimization, cleanup, and best practices.
...
5
votes
2answers
168 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 ...
5
votes
2answers
125 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 ...
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:
...
4
votes
2answers
363 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 ...
4
votes
1answer
60 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
112 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 ...
4
votes
1answer
493 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 ...
4
votes
1answer
6k views
Create a tree from a list of nodes with parent pointers only
I want you to pick my code apart and give me some feedback on how I could make it better or more simple.
...
4
votes
4answers
1k views
Check if a Binary Tree <String> is aBinary Search Tree
I'm understanding the question, but I want to know whether or not my implementation is correct.
The question is:
Write a method that accepts as its argument a BinaryTree object and
returns true ...
4
votes
1answer
113 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 ...
4
votes
1answer
1k views
Recursive search to delete n'th child in tree
I have to implement a tree programming here. What I mean by tree programming is I have data stored in tree format. I have a parent object which will have child objects of same type the level of ...
4
votes
1answer
352 views
Binary Tree Level Order Traversal Algoritm
I am trying to solve this Binary tree lever order traversal
...
3
votes
2answers
137 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 ...
3
votes
2answers
174 views
Least common ancestor in binary tree
This code finds a common ancestor. If one of the input does not exist in the tree then throws an exception. This does not use extra storage. It does not even traverse more than what it should be. It ...
3
votes
2answers
238 views
Binary Tree Operations
I've been programming for about 5 years now, mostly in C++ and Java, while continuing my college education in Computer Science. As an adult student, I'm always looking for opinions and ways to improve ...
3
votes
1answer
327 views
3
votes
1answer
266 views
Expression tree creation from postfix expression
Given a postfix expression, construct an expression tree. Looking code code review, optimizations and best practices.
...
3
votes
1answer
76 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 ...
3
votes
2answers
276 views
BinaryTree class with extra methods
I am taking a data structures course. I would like to check whether my BinaryTree code is perfect, fine or has lots of mistakes.
I would like any kind of advice ...
3
votes
1answer
125 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
...
3
votes
2answers
124 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. ...
3
votes
2answers
785 views
Creating a binary search tree
I want you to pick my code apart and give me some feedback on how I could make it better or simpler. Although, agree that generics should be used, instead of integers, let's punt on generics as a ...
3
votes
1answer
1k views
Print path (leaf to root) with max sum in a binary tree
I want you to pick my code apart and give me some feedback on how I could make it better or more simple.
...
3
votes
1answer
270 views
Binary Search Tree insert method (map interface)
This is my implementation based on Map<K,V> interface. The BST is a linked binary tree with root reference, both internal and external nodes (...
3
votes
1answer
31 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:
...
3
votes
1answer
717 views
non-recursive tree traversal, code review request
Ok, code reviewers, I want you to pick my code apart and give me some feedback on how I could make it better or more simple.
...
3
votes
1answer
196 views
Convert tree to circular doubly linked list
I want you to pick my code apart and give me some feedback on how I could make it better or simpler. This code converts a binary tree to a doubly linked list (in order).
...
3
votes
0answers
46 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.
...
2
votes
3answers
148 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.
...
2
votes
2answers
291 views
2
votes
1answer
511 views
Least common ancestor for binary search tree
I want you to pick my code apart and give me some feedback on how I could make it better or more simple. This code finds a common ancestor for binary search tree. This code accounts duplicates as ...
2
votes
1answer
282 views
Printing the values on each level of a Binary Tree
The below code is for printing level-by-level in a binary tree:
...
2
votes
1answer
62 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.
...
2
votes
2answers
140 views
In-order Predecessor BST review
I was referred here from StackOverflow, so here is what I posted over there:
So, for an assignment, I have to construct a binary search tree, plus an assortment of related functions. I have them all ...
2
votes
1answer
2k views
Find height of a tree without using recursion
I want you to pick my code apart and give me some feedback on how I could make it better or simpler.
...
2
votes
1answer
42 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 ...
2
votes
1answer
680 views
Finding inorder successor
I want you to pick my code apart and give me some feedback on how I could make it better or more simple. This code finds inorder successor in a binary tree.
...
1
vote
3answers
265 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:
...
1
vote
3answers
112 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.
...
1
vote
1answer
330 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 - ...