GATE Exam  >  GATE Questions  >   Consider the following code for inorder trav... Start Learning for Free
Consider the following code for inorder traversal of a binary tree.
Void traversal (node *root)
{
if (root ==0)
{
Print f(“empty tree”);
}
else
{
itraversal (root left);
printf("%d\n”, root data);
Iiraversal (root right);
}
}
Which of the following is true about the above snippet of code.
  • a)
    It prints inorder traversal and then prints “empty tree” infinite times.
  • b)
    It prints only inorder traversal of tree
  • c)
    It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).
  • d)
    It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.
Correct answer is option 'D'. Can you explain this answer?
Verified Answer
Consider the following code for inorder traversal of a binary tree.Vo...
“Empty tree” will be printed (N+1) times in addition to inorder traversal. It is so because, if root is zero, the control has to return, but it instead just prints “empty tree” (N+1) times, because for a binary tree with N nodes, there are (N+1) empty nodes.
View all questions of this test
Explore Courses for GATE exam
Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer?
Question Description
Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer?.
Solutions for Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer?, a detailed solution for Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer? has been provided alongside types of Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following code for inorder traversal of a binary tree.Void traversal (node *root){if (root ==0){Print f(“empty tree”);}else{itraversal (root left);printf("%d\n”, root data);Iiraversal (root right);}}Which of the following is true about the above snippet of code.a)It prints inorder traversal and then prints “empty tree” infinite times.b)It prints only inorder traversal of treec)It prints inorder traversal and also prints “empty tree” 2N times (“N” is number of total nodes in tree).d)It prints inorder traversal of tree and also prints “empty tree” (N+1) times, where N is the total number of nodes in tree.Correct answer is option 'D'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev