Select The Code Snippet Which Performs Levelorder Traversal #541
Select the code snippet which performs level-order traversal.
This multiple choice question (MCQ) is related to the book/course gs gs121 Data Structures and Algorithms. It can also be found in gs gs121 Binary Trees - Inorder Traversal - Quiz No.1.
Select the code snippet which performs level-order traversal.
public static void levelOrder(Tree root) { Queue<Node> queue=new LinkedList<Node>(); queue.add(root); while(!queue.isEmpty()) { Node tempNode=queue.poll(); System.out.println("%d ",tempNode.data); if(tempNode.left!=null) queue.add(tempNode.left); if(tempNode.right!=null) queue.add(tempNode.right); } }
public static void levelOrder(Tree root) { Queue<Node> queue=new LinkedList<Node>(); queue.add(root); while(!queue.isEmpty()) { Node tempNode=queue.poll(); System.out.println("%d ",tempNode.data); if(tempNode.left!=null) queue.add(tempNode.right); if(tempNode.right!=null) queue.add(tempNode.left); } }
public static void levelOrder(Tree root) { Queue<Node> queue=new LinkedList<Node>(); queue.add(root); while(!queue.isEmpty()) { Node tempNode=queue.poll(); System.out.println("%d ",tempNode.data); if(tempNode.right!=null) queue.add(tempNode.left); if(tempNode.left!=null) queue.add(tempNode.right); } }
public static void levelOrder(Tree root) { Queue<Node> queue=new LinkedList<Node>(); queue.add(root); while(!queue.isEmpty()) { Node tempNode=queue.poll(); System.out.println("%d ",tempNode.data); if(tempNode.right!=null) queue.add(tempNode.left.left); if(tempNode.left!=null) queue.add(tempNode.right.right); } }
Similar question(s) are as followings:
Online Quizzes of gs121 Data Structures and Algorithms
Binary Trees - Binary Search Tree - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Binary Search Tree - Quiz No.2
gs gs121 Data Structures and Algorithms
Online Quizzes
Binary Trees - Preorder Traversal - Quiz No.1
gs gs121 Data Structures and Algorithms
Online Quizzes