Questions tagged [tree-traversal]
Challenge related to the concept of trees present in graph theory.
22 questions
20
votes
12
answers
2k
views
Recognize a counting tree
Let a counting tree be a rooted tree in which every node is labeled with the number of descendants it has.
We can represent such trees as ragged lists with each node being represented by a list ...
8
votes
4
answers
322
views
Your trees need to be rerooted
In graph theory a tree is just any graph with no cycles. But in computer science we often use rooted trees. Rooted trees are like trees except they have one specific node as the "root", ...
13
votes
11
answers
1k
views
The longest consecutive traversal possible (number of edges)
A truck fleet dispatcher is trying to determine which routes are still accessible after heavy rains flood certain highways. During their trips, trucks must follow linear, ordered paths between ...
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 ...
7
votes
4
answers
370
views
Regrowing trees
Background
Here you have another work-inspired challenge, but from my wife's work in this case. Imagine you have a service that returns the list of nodes in a tree structure (much like the files and ...
9
votes
2
answers
423
views
Compute the height of a radix tree
Introduction
A radix tree, also known as compressed trie or compressed prefix tree, is a tree-like data structure for storing a set of strings.
The edges of the tree are labeled by nonempty strings, ...
15
votes
5
answers
760
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,...
12
votes
2
answers
349
views
Creasing for Loot
Introduction
After a long battle, you have managed to defeat a Sphinx in a contest of riddles. The Sphinx, impressed with your skill, wishes to give you a reward commensurate with your cleverness, ...
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 ...
2
votes
1
answer
565
views
How can I make this program smaller? [closed]
I am trying my hand at writing super small programs. I wrote a simple "tree" display program for showing a graphical representation of a folder hierarchy. I have made it small in all the ways I can ...
13
votes
8
answers
7k
views
Binary tree encoding [closed]
Let's suppose you have a complete binary tree (i.e. each internal node has exactly two non empty descendants). Each node contains a nonzero integer. You are given the task of encoding and decoding the ...