Questions tagged [tree]

A tree is a widely-used data structure that emulates a hierarchical tree-like structure with a set of linked nodes.

A tree is a data structure where each node has a number of child nodes. By starting at the first node (called the root), one can use a decision algorithm to determine which of the children of the current node is the most appropriate for the next processing or traversal step.

Operations on trees include insert, delete, traverse and find. The algorithms for these methods are usually recursive, starting from the root node and recursively calling its left and right child.

Below is an example of binary-tree, in which each node has up to two child nodes:

binary tree

Because large portions of the remaining nodes are culled away with each decision, properly balanced trees typical yield logarithmic time lookups, inserts, and deletes when used for storage.


Useful links


Related tags

16659 questions
4
votes
2 answers

Efficient equality function on trees

A few days ago, I was given the following interview question. It was described with Standard ML code, but I was free to answer with the language of my choice (I picked Python): I have a type: datatype t = Leaf of int | Node of (t * t) and a…
Patrick Collins
  • 10,306
  • 5
  • 30
  • 69
4
votes
1 answer

Haskell Pre-order Traversal Tree to List

I am having trouble getting my code to do a preorder traversal of a tree to a list to work. The definition for the tree is as follows: data Tree a b = Branch b (Tree a b) (Tree a b) | Leaf a and my definition for preorder traversal is as…
4
votes
1 answer

Angular Tree Directive with Lazy Loading

We are kicking a new project using angularJS :) and one of the requirements is a tree control. The tree control should support "Lazy Loading", So we could add nodes to it dynamically as we get more data using AJAX. I saw the 2 directives below, but…
Avi Kessel
  • 96
  • 1
  • 9
4
votes
1 answer

fatal: git write-tree failed to write a tree

I have a private repository in bitbucket.There are two branch one is master and anoter is eventdesign. Designer does design in eventdesign branch.Now, i want to merge the eventdesign branch with the master so that i can use the design.i used the…
Drudge Rajen
  • 7,584
  • 4
  • 23
  • 43
4
votes
1 answer

Setting dijit.Tree cookie for all pages

I'm using the same dijit.Tree view over several pages in our application, and I'd like to have the cookie saved for the server name, instead of the folder name. Right now I've got 3 pages and 3 cookies, which each hold their own information on the…
peirix
  • 36,512
  • 23
  • 96
  • 126
4
votes
2 answers

Definition of tree structure in Lisp

From the Common Lisp HyperSpec glossary: tree n. 1. a binary recursive data structure made up of conses and atoms: the conses are themselves also trees (sometimes called "subtrees" or "branches"), and the atoms are terminal nodes (sometimes …
Jisang Yoo
  • 3,670
  • 20
  • 31
4
votes
2 answers

Merge two trees on equal nodes

Nodes are equal when their IDs are equal. IDs in one tree are unique. On the schemas, IDs of nodes are visible. Consider tree1: root | +-- CC | | | \-- ZZZ | | | \-- UU | \-- A | \-- HAH And…
Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110
4
votes
6 answers

Binary Search or Btree index update issue

Imagine that you are handed a new book everyday from an author. The book is a work in progress. He does not tell you what he has changed or added. Your job is to identify the changes and additions, and pass ONLY these along to the publisher (who…
Mike Trader
4
votes
1 answer

Create a Tree from a list of items, when each item contains a reference to its parent

I have a list of objects of type Foo. Each Foo object contains a reference to its parent: public class Foo { public Foo Parent { get; set; } } (If Parent is null, then the Foo is considered to be a 'root' node.) As you can see, this implies a…
BTownTKD
  • 7,911
  • 2
  • 31
  • 47
4
votes
1 answer

Passing Binary Tree on a network with minimum space

I recently came across an interview question asked by Amazon : Given a binary tree to be passed through a network. How to pass this tree in minimum space? Ok, my 2 approaches to above question are: We can store the inorder of tree in an array…
Ayush
  • 2,608
  • 2
  • 22
  • 31
4
votes
1 answer

Access declarations are deprecated in favor of using-declarations; suggestion: add the ‘using’ keyword

I returned to one of my old C++ school assignments which implemented a binary tree. I have a file (Tree.cpp) that contains functions to insert, lookup, remove, etc nodes. At the top, I have "using namespace std;". The warnings I am getting are…
user3750325
  • 1,502
  • 1
  • 18
  • 37
4
votes
1 answer

Alignment of nodes on d3.js graph

Please see http://jsbin.com/okUxAvE/28. Then click on query. Notice how the children start displaying at the same level as query. Now pan down to methods (a child of query) and click this one to expand it. Note how the children of method expand…
stephenhay
  • 2,824
  • 24
  • 25
4
votes
4 answers

How to build nested menu "trees" in HAML

I am trying to build a simple nested html menu using HAML and am not sure how to go about inserting the elements with the correct indentation, or the general best way to build nested trees. I would like to be able to do something like this, but…
Lance
  • 75,200
  • 93
  • 289
  • 503
4
votes
2 answers

Strategy to sharing data across an object tree without using static members

I am in a situation where I need to share data across many instances of a polymorphic object tree, but then again, I need the shared data to be "per-tree" so using static class members in the base class is no really an option. I don't want to…
user3735658
4
votes
3 answers

What happens to an array during recursion in C?

In the following code I try to print all paths from the root to leaves in a Binary Tree. If I write a recursive function as follows : void printPath(BinaryTreeNode * n, int path[],int pathlen) { //assume base case and initializations…
Dubby
  • 1,154
  • 3
  • 16
  • 31
1 2 3
99
100