Tagged Questions
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.
4
votes
1answer
88 views
+100
MutationObserver (shim): Finding differences between 2 trees
I've been working on a MutationObserver es5 shim and would appreciate some feedback on my technique for identifying changes between a node and its clone from earlier state. The reason I'm asking for ...
0
votes
0answers
30 views
Incorrect Insertion in Balanced Binary Tree [closed]
I am trying to implement Insertion operation in Balanced Binary Tree through the following code:-
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node *left, *right;
...
0
votes
0answers
18 views
AVL Tree question regarding insertion [closed]
I am implementing a map data type using an AVL tree, as an assignment in my algorithms and
data structures class. It is auto - tested after being sent by the server with this test:
AVLStabloMapa ...
0
votes
1answer
36 views
Serializing/deserializing binary tree in most space-efficient way
I'm looking for corrections, optimizations, general code review, etc.
final class TreeData<T> {
private T item;
private boolean left;
private boolean right;
public TreeData(T ...
1
vote
0answers
35 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
42 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
74 views
Max depth of tree when all parent pointers are provided
Request for optimization, good practices, recommendations.
class NodeMaxDepth {
private final NodeMaxDepth parent;
public NodeMaxDepth (NodeMaxDepth parent) {
this.parent = parent;
...
3
votes
1answer
62 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 manner - column wise. Note that, 8, ...
5
votes
1answer
166 views
Prims algorithm implementation
Review this code regarding optimization, cleanup, and best practices.
final class EdgePrims<T> {
private final T source, target;
private final int distance;
public EdgePrims(T ...
5
votes
1answer
67 views
Simple prefix tree
I've written a simple function for building a prefix tree (and searching):
import qualified Data.List as L
import qualified Data.Map as M
data Tree a = Empty | Node a [Tree a] deriving (Show, Eq)
...
4
votes
2answers
75 views
Printing out a binary tree level by level
Below is my implementation for an interview question of printing a binary tree level by level. I've also included some methods for creating a binary tree from a vector in my solution. Please review ...
2
votes
2answers
70 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 ...
0
votes
1answer
279 views
Implementation of Prim's minimum spanning tree
Feel free to tell about every possible issue (style, errors, inffective solution etc.) you found. Here is the main part of what I want to be reviewed, through there is some related code on GitHub.
...
4
votes
0answers
636 views
Performance of List representation of MonadPlus versus Tree representation
I am working on a code where I represent a MonadPlus using a Tree data structure and then explore it, summing over all of the leaves (whose type must be an instance of Monoid); I need to use a Tree ...
0
votes
2answers
45 views
How to enumerate the internal nodes and leaves of a tree more elegantly?
Might there be a simpler way to write this code?
This is the code I have, and I'd like to learn to write code more efficiently.
Thank you.
def leaves_and_internals(self):
"""(BTNode) -> ...
3
votes
2answers
166 views
Returning a list of the values from the binary tree
I want to return a list of the values from the binary tree. Is there a shorter and more efficient way to write the method for numbers?
class BTNode(object):
"""A node in a binary tree."""
...
2
votes
2answers
191 views
Building a Red Black tree using a structure as a node
I have the following structure:
struct Keys
{
//value of word in the vector<string> words.
string word;
//index of word in the vector<string> words.
int index;
//I want to ...
0
votes
0answers
32 views
Improvements to my binary tree written in CoffeeScript
This is my attempt at a binary tree. I'm using it only for ordering a LDAP user list. My need is for storing multiple objects, so this tree is limited to leaves that are objects (see data = {[..]}.
...
0
votes
1answer
474 views
Breadth-first tree traversal using STL list
I am writing code for breadth-first search of a tree with C++'s STL. Please help as I am new to the STL.
#include<iostream>
#include<malloc.h> //on llvm we don't need this
...
1
vote
1answer
2k views
Arithmetic expression parsing, and converting infix to postfix notation
I'm doing a infix to postfix conversion. The code works, but here are some points I want to improve
1) In the line of
while ((!operators.empty())&&(order(operators.top()) >= ...
1
vote
1answer
116 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.
public class Trie {
private static final int ASCII = 256;
...
0
votes
0answers
88 views
Join levels of binary tree - Code review request
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
174 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).
public class CreateABinaryTree {
...
2
votes
2answers
97 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
95 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 preorder array contains ...
1
vote
1answer
343 views
Find height of a tree without using recursion, 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.
public int heightHelper(TreeNode node) {
int height = -1;
...
0
votes
0answers
36 views
Print duplicate and its frequency in BST assuming duplicates allowed only on right subtree.
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.
public class DuplicateCountInBST {
private TreeNode root;
...
1
vote
1answer
71 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.
public class PrintAllPath {
private TreeNode root;
private class ...
3
votes
1answer
172 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.
public class NonRecursiveTraversal {
private TreeNode root;
...
1
vote
1answer
243 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.
public class MaxSumPath {
private TreeNode root;
private static ...
4
votes
1answer
493 views
Create a tree from a list of nodes with parent pointers only. Critique 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.
class TreeNode {
private TreeNode left;
private TreeNode right;
...
2
votes
1answer
157 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.
public class Successor {
private ...
2
votes
1answer
106 views
Convert tree to circular doubly Linkedlist - critique 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.This code converts a binary tree to a doubly linkedlist (indorder).
public ...
1
vote
2answers
32 views
Print periphery of a binary tree, critique 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. This code will traverse peripheri ( clock and anticlockwise ) in O(n) just ...
1
vote
0answers
51 views
Construct a tree given pre and inorder Or post and inorder - critique 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. For a Full-Tree (all nodes with 0 or 2 children) it works ...
3
votes
1answer
301 views
LinkedList and Binary Search Tree in Javascript
I recently decided to make a LinkedList and Binary Search Tree using JavaScript. I wanted to reach out to a wider audience and see how I did, and where could I improve.
Linked List: ...
0
votes
1answer
125 views
Least common ancestor for binary search tree
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. This code finds a common ancestor for binary search tree. this code ...
0
votes
0answers
68 views
Least common ancestor in binary tree
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. This code finds a common ancestor. If one of the input does not exist in ...
3
votes
1answer
2k views
My Red-Black Tree Implementation
I worked on a Red-Black tree implementation in C++, and it works as it should. However, I want to see what else I can do to make this code faster/more clean, etc.
Any particular suggestions?
Edit: ...
1
vote
0answers
178 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 (MyBSNode) contains (key, value) entries
What do you ...
0
votes
2answers
326 views
Preorder traversal using stack
I wrote the code for an iterative pre-order traversal using stack for binary search tree. Below is the code for same. Please help me verify the correctness of the algorithm. Here t.t is the value of ...
1
vote
1answer
47 views
Complexity Of Determining Tree is balanced?
boolean isBalance(Node root) {
if (root == null )
return true;
return Math.abs(getHeight(root.left)-getHeight(root.right)) <=1;
}
int getHeight(Node N) {
int L = 0;
int R ...
3
votes
2answers
145 views
Java Binary Tree Improvement Critiques
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 ...
2
votes
1answer
61 views
tree heap Haskell code
I'd like a review of Haskell tree heap code in Turning a tree into a heap in Haskell.
module Heapify where
data Tree a = Leaf a | Node (Tree a) a (Tree a)
deriving Show
ourTree = Node (Node ...
4
votes
4answers
555 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
2answers
568 views
Tree Node class - deallocation in the destructor
Is my destructor correct? Does it properly deallocate the subtrees?
#ifndef HEADER_GUARD__TREE
#define HEADER_GUARD__TREE
#include <deque>
namespace Sandbox {
class Node {
public:
...