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.
33 questions
8
votes
6
answers
1k
views
Ranking of binary trees
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 ...
11
votes
13
answers
1k
views
Number of complete binary unordered tree-factorizations of n
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
$...
11
votes
14
answers
851
views
Increasing permutation trees
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 ...
12
votes
1
answer
312
views
Create Word Lightning
Sandbox
Inspired by a Codingame challenge I tried (and failed at) about a month ago.
Given a binary tree of words, say:
...
4
votes
3
answers
6k
views
The Great Battle Conundrum- Who are Alive?
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 ...
20
votes
20
answers
3k
views
Fibonacci trees
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 \$...
5
votes
8
answers
708
views
Shortest Program To Find Lowest Common Ancestor of Two Nodes in a Binary Tree
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 ...
20
votes
20
answers
7k
views
Write The Shortest Program to Calculate Height of a Binary Tree
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:
...
17
votes
7
answers
1k
views
Binary tree rotations
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 ...
20
votes
9
answers
2k
views
Enumerate binary trees
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 ...
46
votes
4
answers
3k
views
Build an aesthetically pleasing divisor tree
An aesthetically pleasing divisor tree is a tree of divisors of input n that, for any composite number m, has two children nodes ...
10
votes
1
answer
322
views
Tree traversing
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, ...
7
votes
5
answers
5k
views
Convert binary search tree into ordered linked list
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 ...
8
votes
6
answers
2k
views
Fix your trees!
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 ...
16
votes
10
answers
3k
views
Find a fraction's position in the Stern-Brocot tree
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 ...
10
votes
5
answers
982
views
Huffman golfing [duplicate]
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 ...
14
votes
5
answers
12k
views
Free a Binary Tree [closed]
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 ...