UVa 122

From Algorithmist
Jump to: navigation, search

Contents

[edit] 122 - Trees on the Level

[edit] Summary

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

[edit] Explanation

Straight forward binary tree implementation.

[edit] Optimizations

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

[edit] Gotchas

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.

[edit] Input

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

[edit] Output

5 4 8 11 13 4 7 2 1
not complete

[edit] External links

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

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox