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. ...
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 ...
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
363 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 ...
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. ...
3
votes
1answer
236 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
247 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 ...
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 ...
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: ...
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 ...
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: ...
1
vote
3answers
257 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
335 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. ...
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 ...
0
votes
1answer
851 views

Serializing/deserializing binary tree in most space-efficient way

I'm looking for corrections, optimizations, general code review, etc. ...
3
votes
2answers
123 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
141 views

Max depth of tree when all parent pointers are provided

Request for optimization, good practices, recommendations. ...
4
votes
1answer
477 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. ...
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
2answers
289 views

Generic binary search tree implementation

I use this interface for my BST node class: ...
1
vote
1answer
445 views

Trie - code review request for improvement

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. ...
-1
votes
1answer
227 views

Join levels of binary tree

Please ignore feedback to include generics and function renaming while giving me feedback. Names of functions have been deliberately kept the way they are for time-being. Also please let me know if ...
1
vote
1answer
3k views

Create a binary tree, 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. ( Generics would be added a bit later). ...
3
votes
2answers
750 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 ...
1
vote
1answer
124 views

Given preorder array construct a BST

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. Also its really hard to make this code work if ...
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. ...
5
votes
1answer
105 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 ...
1
vote
1answer
289 views

Print all path from root to leaves - 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
687 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
987 views

Print path(leaf to root) with max sum in a binary tree - 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. ...
4
votes
1answer
5k 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. ...
2
votes
1answer
647 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. ...
3
votes
1answer
190 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). ...
1
vote
1answer
91 views

Construct a tree given pre and inorder or post and inorder

I want you to pick my code apart and give me some feedback on how I could make it better or simpler. For a full tree (all nodes with 0 or 2 children) it works deterministically: ...
2
votes
1answer
493 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 ...
3
votes
2answers
172 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 ...