Skip to main content

Questions tagged [binary-tree]

A high-level data structure, made of nodes, each with a maximum of 2 children (left and right). Nodes with no children are called leaves, and two nodes with the same parent are known as siblings.

Filter by
Sorted by
Tagged with
8 votes
6 answers
1k views

Let N = [0,1,2,...n-1] be the initial segment of the natural numbers of length n, then all permutations of N can be sorted lexicographically, starting with the identity. The index into this sorted ...
Sophia Antipolis's user avatar
11 votes
13 answers
1k views

For prime p, the factorization tree is a single vertex in just one way so that a(p) = 1. For composite n, the two subtrees at n are a split of n into two factors n = d * (n/d), without order, so that $...
Sophia Antipolis's user avatar
11 votes
14 answers
851 views

For this challenge a "binary tree" is a rooted tree where each node has 0 children (leaf) or 2. The children of a node are unordered, meaning that while you might draw the tree with left ...
Wheat Wizard's user avatar
  • 103k
12 votes
1 answer
312 views

Sandbox Inspired by a Codingame challenge I tried (and failed at) about a month ago. Given a binary tree of words, say: ...
Razetime's user avatar
  • 27.6k
4 votes
3 answers
6k views

Maximillian is the chief commander of the Great Greek Army and he is leading his forces into a crucial war with Spain. If all the enemy soldiers stand in a straight line incrementally marked starting ...
Pluviophile's user avatar
20 votes
20 answers
3k views

Background Fibonacci trees \$T_n\$ are a sequence of rooted binary trees of height \$n-1\$. They are defined as follows: \$T_0\$ has no nodes. \$T_1\$ has a single node (the root). The root node of \$...
Bubbler's user avatar
  • 79.3k
5 votes
8 answers
708 views

Any two separate nodes in a binary tree have a common ancestor, which is the root of a binary tree. The lowest common ancestor(LCA) is thus defined as the node that is furthest from the root and that ...
T. Salim's user avatar
  • 665
20 votes
20 answers
7k views

The height of a binary tree is the distance from the root node to the node child that is farthest from the root. Below is an example: ...
T. Salim's user avatar
  • 665
17 votes
7 answers
1k views

Balanced binary search trees are essential to guarantee O(log n) lookups (or similar operations). In a dynamic environment where a lot of keys are randomly inserted and/or deleted, trees might ...
ბიმო's user avatar
20 votes
9 answers
2k views

Binary trees A binary tree is a tree with nodes of three types: terminal nodes, which have no children unary nodes, which have one child each binary nodes, which have two children each We can ...
Guy Coder's user avatar
  • 321
46 votes
4 answers
3k views

An aesthetically pleasing divisor tree is a tree of divisors of input n that, for any composite number m, has two children nodes ...
Sherlock9's user avatar
  • 12.4k
10 votes
1 answer
322 views

Have you heard about trees? When performing DFS on a binary tree, you can traverse it in 3 possible orders. Root, left node, right node (Pre-order) Left node, Root, right node (In-order) Left node, ...
jkklapp's user avatar
  • 126
7 votes
5 answers
5k views

Write the shortest possible program that turns a binary search tree into an ordered doubly-linked list, by modifying the pointers to the left and the right children of each node. Arguments: a pointer ...
user avatar
8 votes
6 answers
2k views

In informatics, we often use trees in lots of different forms and representations. The three major methods of serialising binary trees are prefix, infix and postfix notation. For example, the ...
tomsmeding's user avatar
  • 2,054
16 votes
10 answers
3k views

The Stern-Brocot tree is a binary tree of fractions where each fraction is acquired by adding the numerators and denominators of the two fractions neighbouring it in the levels above. It is generated ...
Joe Z.'s user avatar
  • 35.5k
10 votes
5 answers
982 views

Write a filter that converts text from standard input to a representation of its Huffman tree on standard output. In as few characters as possible. you're free to consider newlines or not output ...
J B's user avatar
  • 10.1k
14 votes
5 answers
12k views

So before you read some basic computer science concepts. A binary tree is a dynamically allocated structure (usually used for ordered storage). Because of its nature traversal of binary trees is ...
Loki Astari's user avatar