In computer science, a tree is a widely used abstract data type (ADT) or data structure implementing this ADT that simulates a hierarchical tree structure, with a root value and subtrees of children, represented as a set of linked nodes.

learn more… | top users | synonyms

0
votes
2answers
31 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) -> ...
2
votes
2answers
70 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
1answer
96 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
530 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
70 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
42 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
50 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 { ...
1
vote
2answers
58 views

Create a binary search 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. Although, agree that generics should be used, instead of integers, lets ...
1
vote
0answers
41 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
72 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
16 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
43 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
75 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
62 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
121 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; ...
1
vote
1answer
41 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
72 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
27 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
37 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 ...
2
votes
1answer
103 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
68 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
41 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
419 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
74 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
118 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
46 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
118 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
57 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 ...