Question: To class Tree, add the following methods: 1 - nodesInLevel ( int x ) : it returns number of nodes in a specific level x

To class Tree, add the following methods:
1- nodesInLevel(int x): it returns number of nodes in a specific level x.
for example in this tree, nodesInLevel(2) is 4(assuming that root is in
level 0). Hint: this method should call a recursive method.
2- ancestors( int k): it prints all ancestor of the node with key k starting
by the parent toward the root.
For example ancestors(31), it prints: 43,19,11.
Hint: you need to use a stack.
3- printByLevel() which prints all nodes in the tree level by level, it prints all nodes in a specific level
before moving to the nodes at the next depth level. For example this tree should be printed as
follows:
11,6,19,4,8,17,43,5,10,31,49
Hint: you need to use a queue.
To class Tree, add the following methods: 1 -

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 Programming Questions!