Question
Derive a O ( n ) method valuesInLevelOrder() that returns a list of the nodes of a binary tree in level-order. That is, the method
Derive a O(n) method valuesInLevelOrder() that returns a list of the nodes of a binary tree in level-order. That is, the method should return the root, then the nodes at depth 1, followed by the nodes at depth 2, and so on. Your algorithm should begin by putting the tree root on an initially empty queue. Then dequeue a node, add it to the output, and enqueue its left and right children (if they exist). Repeat until the queue is empty.
Node.java
import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue;
public class Node
public Node() {
}
public Node(E data) { this.data = data; }
public Node(Node
public Node(E data, Node
public static List
}
public static void main(String [] args) {
} }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started