UVa 122

From Algorithmist
Jump to navigation Jump to search

122 - Trees on the Level[edit]

Summary[edit]

Print the nodes of a completely specified binary tree in breadth-first order.

Explanation[edit]

Straight forward binary tree implementation.

Optimizations[edit]

None really needed. Even a linked nodes implementation is plenty fast enough to pass.

Gotchas[edit]

The definition of "completely specified" means that the number of input nodes equals the size of the tree. Duplicate values are permitted. Don't print any trailing spaces in your output.

Input[edit]

(11,LL) (7,LLL) (8,R)
(5,) (4,L) (13,RL) (2,LLR) (1,RRR) (4,RR) ()
(3,L) (4,R) ()

Output[edit]

5 4 8 11 13 4 7 2 1
not complete

External links[edit]

Breadth-first order - Wiki link
Binary Tree - Wiki link