Question: In Java: Write a method findHeight() that returns the height of the calling tree. Remember that the height is the maximum level of the tree,

In Java:

Write a method findHeight() that returns the height of the calling tree. Remember that the height is the maximum level of the tree, with level 1 being the root. (Hint: A recursive solution is nice and short.)

In class we discussed pre-order, in-order, and post-order traversals. Another common type of tree traversal is a level-order traversal. This involves visiting the nodes of the tree left-to-right, top-to-bottom (just like the way you normally read a page of text). For example, consider the BST below:

A level-order traversal would visit the nodes in this order: 5 0 7 4 9 1

Write a levelOrderTraversal method. The method should print the nodes in the order that they are visited. (Hint: one non-recursive algorithm for this is to use a queue to keep track of the nodes that you want to visit. Start by enqueuing the root node, and see what needs to be done from there.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!