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.

learn more… | top users | synonyms

26
votes
1answer
364 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 that are the pair of divisors that are closest to the square root of m. ...
9
votes
3answers
206 views

Pre-order + post-order to in-order

Task Given the pre-order and post-order traversals of a full binary tree, return its in-order traversal. The traversals will be represented as two lists, both containing n distinct positive integers,...
6
votes
1answer
155 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
1answer
312 views

Print a non-clashing binary search tree

Brief Print an ASCII representation of a binary search tree. You should write your own minimum implementation logic of a BST (node, left, right, insert) (50,30,70,20,80,40,75,90) gives: ...
5
votes
5answers
938 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
6answers
814 views

Find a binary tree's deepest node

Write a program that takes a binary tree as input, and outputs the deepest node and its depth. If there is a tie, print all involved nodes as well as their depths. Each node is represented as: T(x,x) ...
6
votes
6answers
1k 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 ...
14
votes
9answers
2k views

Create Balanced BST from Sorted List of Integers

Given a unique, sorted list of integers, create a balanced binary-search tree represented as an array without using recursion. For example: func( [1,2,3,5,8,13,21] ) => [5,2,13,1,3,8,21] Before ...
10
votes
7answers
718 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 ...
9
votes
6answers
1k views

Enumerate all binary trees with n nodes

Given an integer n, enumerate all possible full binary trees with n internal nodes. (Full binary trees have exactly 2 children on every internal node). The tree structure should be output as a pre-...
9
votes
5answers
683 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 ...
16
votes
5answers
3k views

Print a Binary Tree

Inspired by a recent question on SO... Write a function to print a binary tree in the following format: 3 / \ 1 5 \ / \ 2 4 6 The output should consist of a line of nodes, followed ...
12
votes
4answers
2k views

Free a Binary Tree

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 ...