Memoirs of a Technocrat

by Niroshan Rajadurai

  • Increase font size
  • Default font size
  • Decrease font size

Binary Tree

E-mail Print PDF
User Rating: / 0
PoorBest 

Suppose you have a binary tree containing N nodes. Each node has a Name, a LeftChild and a RightChild. Write a C++ function to print the tree by levels. Print the root first, then all the children of the root, then all the grandchildren of the root, etc.Your algorithm must take O(n) time.

 

  1. Provide an implementation for: void printNodes(const Node * root);
  2. What assumptions does your code make?
  3. Did you use a computer to do this?
  4. How long did it take to do this question?

 

Comments (0)
Last Updated on Monday, 24 January 2011 12:28