Would you please help me with this question?
Using Big O Notation, what is the running time of the level-order traversal ( the code below) in terms of the number of nodes N and the tree height h? Based on your knowledge of the possible values of h, what are the average, best, and worst running times in terms of just N? would you please explain to me?
Expand|Select|Wrap|Line Numbers
- void Tree<T> :: level_order_traversal(std::ostream& out, TreeNode<T>*
- rootNode)
- {
- Queue <TreeNode<T>*> queue;
- int dep; //depth of the node
- int temp=0;
- queue.enter(root);
- while (!queue.isEmpty()) {
- rootNode = queue.leave();
- if( depth(rootNode)!=temp){
- temp=depth(rootNode);
- out<<"\n";
- }
- out<<rootNode->data<<" ";
- if (rootNode->left!= NULL)
- queue.enter(rootNode->left);
- if (rootNode->right != NULL){
- queue.enter(rootNode->right);
- }
- }
- }