Breadth First Tree Traversal

Write an algorithm that takes a tree data structure and writes out all the elements in a breadth-first traversal order.


Problem Statement

Write pseudo-code that takes a tree data structure and writes out all the elements in a breadth-first traversal order.


Evaluation


  • Completeness of pseudo-code algorithm (25%)

  • Correctness of the algorithm, demonstrated by quick manual unit tests (25%)

  • What is the time and space complexity in the average and worst cases? (25%)

  • Change your code to also print a new-line after each level of the tree is written out (25%)


Solution

C# solution courtesy of Paul Hounshell :

Paul's response to part (d) : change ...

to:

where the int is a level. Simple after that.


References

One of my second year course assignments in University of Waterloo

Amin A.

Written by

Amin Ariana

A software entrepreneur from San Francisco