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
3 answers

Git - tidying up a repo

I have got my repo into a bit of a state and want to be able to work my way out of it The repo looks a bit like this (A1, B1, C1 etc are obviously commits) A1 ---- A2 ---- A3 ---- A4 ---- A5 ---- A6 ---- A7 ---- A8 …
Simon Woods
  • 2,223
  • 4
  • 27
  • 34
4
votes
3 answers

On Haskell, there a standard function that performs "scan" on a tree?

I have a tree: a :: Tree Double a = Node 1 [Node 20 [Node 300 [Node 400 [], Node 500 []], Node 310 []], Node 30 [], Node 40 []] I want to apply it an scan…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
4
votes
1 answer

ZigZag and ZigZig operation in splay tree?

consider my tree is like this 5 / \ 3 7 / \ / \ 2 4 6 8 in that, when we search a element 2 that time zigzig operation will be performed, so first we rotate the parent…
Bhuvanesh
  • 1,269
  • 1
  • 15
  • 25
4
votes
1 answer

Change selected nodes style, d3.js collapsible indented tree

I am trying to allow the user a more visual representation of where they are in the tree by highlighting the "selected" node in the tree, as well as displaying an icon, similar to plus/minus, based on whether or not the children are shown. I can't…
David Figura
  • 43
  • 1
  • 5
4
votes
1 answer

Delete a node from a tree and return the resulting forest

I'm coming from a Java background and want to learn some Haskell. Bit stuck at the moment, though. What I want to do is: I have a list of trees where each node has a unique identifier across all trees in the list. Now I want to delete one node out…
Marco
  • 1,430
  • 10
  • 18
4
votes
1 answer

Font Awesome icons for Webix tree nodes

Webix integrates with Font Awesome. But how can Font Awesome icons be used instead of the default folder/file icons in trees to style individual nodes? Here's what I've tried: http://webix.com/snippet/52251623 template only works at the tree…
Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
4
votes
2 answers

LISP binary trees - max depth

Using this way of representing trees: (A (B) (C (D) (E))) (which, from what I've seen I think it's the standard way, but I might be wrong). A / \ B C / \ D E I want to find the maximum depth and construct a list with the nodes from…
user3002428
  • 299
  • 5
  • 17
4
votes
3 answers

How does one store "pointers" to nested nodes in an immutable tree in React/Javascript?

I have a immutable nested tree (mori, immutable-js et al) consisting of arbitrary nodes, think file browser. The tree gets rendered by React. If a component representing a node receives focus, I'd like to: Show an input field on the node component…
Lukas Bünger
  • 4,257
  • 2
  • 30
  • 26
4
votes
3 answers

Convert a string with brackets to tree, Ruby

I have a string "Animals ( Reptiles Birds ( Eagles Pigeons Crows ) )" and I need to return: a = [ { "Animals" => [ { "Reptiles" => nil }, { "Birds" => [ { "Eagles" => nil }, { "Pigeons" =>…
rel1x
  • 2,351
  • 4
  • 34
  • 62
4
votes
5 answers

Level-order in Haskell

I have a structure for a tree and I want to print the tree by levels. data Tree a = Nd a [Tree a] deriving Show type Nd = String tree = Nd "a" [Nd "b" [Nd "c" [], Nd "g" [Nd "h" [], Nd "i" [], …
brain_damage
  • 955
  • 6
  • 20
  • 29
4
votes
1 answer

F# Tree: Node Insertion

This is a question that extends F# Recursive Tree Validation, which I had nicely answered yesterday. This question concerns inserting a child in an existing tree. This is the updated type I'd like to use: type Name = string type BirthYear …
Simon Emil
  • 85
  • 4
4
votes
2 answers

Delete operation in Array Binary Tree

I know you guys are going to complain about having this question being asked again and again. Sorry, but I have not found my answer in Google/Stackoverflow/Forums... etc I am creating an Array Binary Tree (it's not a search one) in Java. 1) My node…
Alex
  • 131
  • 2
  • 11
4
votes
6 answers

How to create Tree with checkboxes using JSON data with Parent Child Relation?

I have JSON data and that JSON data has parent child relation . I Want to create tree structure from it. i found many plugins and libraries but i can't found my requirement . I am getting this JSON data using PHP script. Here is image that has tree…
Deep Shah
  • 1,334
  • 3
  • 20
  • 41
4
votes
2 answers

How to merge trees (and sum counts) using LINQ?

Say I have these classes: public class Option { public int OptionID { get; set; } public bool IsSelected { get; set; } } public class Product { public int ProductID { get; set; } public int Quantity { get; set; } public…
DeMama
  • 1,134
  • 3
  • 13
  • 32
4
votes
2 answers

Scala sum of a binary tree tail recursive

So I have the following code that define a binary tree. sealed abstract class BinTree { def sum = sumAcc(0) def sumAcc(acc: Int): Int } case class NonEmpty(val elem: Int, val left: BinTree, val right: BinTree) extends BinTree { def…
edblancas
  • 73
  • 7
1 2 3
99
100