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 ...
8
votes
5
answers
851
views
Find a fraction's parent in the Stern-Brocot tree
Objective
Given a positive reduced fraction, output its parent in the Stern-Brocot tree. The outputted fraction shall also be reduced.
The Stern-Brocot tree
The Stern-Brocot tree is an infinite-height ...
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
9
answers
1k
views
Decide Contiguous Binary Tree
Objective
Given an unlabelled binary tree, decide whether it is contiguous in indices.
Indices
This challenge gives one-indexing on binary trees. The exact definition expresses all indices in binary ...
11
votes
14
answers
852
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 ...
28
votes
12
answers
2k
views
Rows of the Collatz tree
Consider a binary tree built the following way:
The root node is \$1\$
For a given node \$n\$:
If \$n\$ is odd, its only child is \$2n\$
If \$n\$ is even, one of its children is \$2n\$. If \$\frac {...
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:
...
16
votes
8
answers
363
views
Side to side, not up and down
Task
Given a list of nodes representing a binary tree of positive integers serialized depth-first, return a list of nodes representing the same tree serialized breadth-first. To represent an absent ...
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 ...
17
votes
2
answers
879
views
Count unrooted, unlabeled binary trees of n nodes
An unrooted binary tree is an unrooted tree (a graph that has single connected component and contains no cycles) where each vertex has exactly one or three neighbors. It is used in bioinformatics to ...
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 \$...
8
votes
2
answers
425
views
Deserialize a binary tree breadth-first
Deserializing binary trees depth-first is pretty easy, but doing it breadth-first is (hopefully) harder. Your mission, should you choose to accept it, is to do the latter.
The input will be a 1-D list ...
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 ...
18
votes
11
answers
6k
views
Check If a Binary Tree is Balanced
For each node in a balanced binary tree, the maximum difference in the heights of the left child subtree and the right child subtree are at most 1.
The height of a binary tree is the distance from the ...
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:
...