Tagged Questions
10
votes
1answer
110 views
Good performance when predicting future game states
This question is about my answer to this king-of-the-hill challenge on Code Golf. In short, the purpose of the challenge is to code a slime that, trough various possible moves gains control over an ...
1
vote
0answers
33 views
Deepest left leaf node in a binary tree
Given a Binary Tree, find the deepest leaf node that is left child of its parent. This question is attributed to GeeksForGeeks. Looking for code-review, optimizations and best practices.
...
3
votes
1answer
42 views
Reverse values of alternate nodes of the tree
Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree.
Given tree:
...
0
votes
0answers
23 views
Return the next right node
Given a binary tree, return the next right node. This question is attributed to GeeksForGeeks.
For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 ...
1
vote
1answer
66 views
Get the levels of a binary tree
Given a binary tree, return a list of each level.
I'm looking for a general review and a mention on best-practices, optimization, and verification of my complexities.
Time complexity: \$O(n)\$
...
3
votes
3answers
175 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.
...
1
vote
0answers
35 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
33 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:
...
9
votes
4answers
316 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
89 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.
...
6
votes
2answers
134 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
33 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 ...
4
votes
1answer
69 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
99 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
212 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
140 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
55 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
500 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
114 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
145 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
142 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
76 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
343 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
346 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
131 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
49 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
236 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
433 views
Binary Tree Level Order Traversal Algoritm
I am trying to solve this Binary tree lever order traversal
...
4
votes
1answer
127 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
60 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
105 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
326 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
279 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:
...
5
votes
2answers
419 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
78 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
77 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
349 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
98 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
139 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
962 views
Serializing/deserializing binary tree in most space-efficient way
I'm looking for corrections, optimizations, general code review, etc.
...
3
votes
2answers
130 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
148 views
Max depth of tree when all parent pointers are provided
Request for optimization, good practices, recommendations.
...
4
votes
1answer
529 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
145 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
298 views
1
vote
1answer
460 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
249 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
889 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 ...