Exam 17: Tree Structures
Exam 1: Introduction98 Questions
Exam 2: Using Objects76 Questions
Exam 3: Implementing Classes103 Questions
Exam 4: Fundamental Data Types125 Questions
Exam 5: Decisions120 Questions
Exam 6: Loops128 Questions
Exam 7: Arrays and Array Lists118 Questions
Exam 8: Designing Classes95 Questions
Exam 9: Inheritance101 Questions
Exam 10: Interfaces85 Questions
Exam 11: Inputoutput and Exception Handling109 Questions
Exam 12: Object-Oriented Design104 Questions
Exam 13: Recursion110 Questions
Exam 14: Sorting and Searching109 Questions
Exam 15: The Java Collections Framework110 Questions
Exam 16: Basic Data Structures104 Questions
Exam 17: Tree Structures110 Questions
Exam 18: Generic Classes75 Questions
Exam 19: Graphical User Interfaces76 Questions
Exam 20: Streams and Binary Inputoutput82 Questions
Exam 21: Multithreading82 Questions
Exam 22: Internet Networking74 Questions
Exam 23: Relational Databases75 Questions
Exam 24: XML74 Questions
Exam 25: Web Applications75 Questions
Select questions type
Given the Node class discussed in section 17.1 (partially shown below), select an expression to complete the isLeaf method, which is designed to return true if the node is a leaf, false otherwise. class Node
{
Public Object data;
Public List<Node> children;
) . .
Public boolean isLeaf()
{
Return _______________;
}
}
Free
(Multiple Choice)
4.8/5
(43)
Correct Answer:
C
What is the complexity of removing an element from a heap?
Free
(Multiple Choice)
4.8/5
(28)
Correct Answer:
B
If the postorder traversal of an expression tree is 8, 2, +, 5, /, what is the numeric result of that Reverse Polish Notation expression?
Free
(Multiple Choice)
4.8/5
(35)
Correct Answer:
D
Consider the following binary search tree:
Which of the following sequences correctly represents postorder traversal of this tree?

(Multiple Choice)
4.9/5
(23)
Consider the following tree diagram:
Which of the following nodes are child nodes?

(Multiple Choice)
4.9/5
(42)
Consider a balanced binary tree with 520 nodes. The average length of all paths from the root to the leaves is approximately ____.
(Multiple Choice)
4.8/5
(40)
Consider the following tree diagram:
Which of the following nodes are siblings?

(Multiple Choice)
4.9/5
(30)
If a min-heap has 14 nodes, what is known for certain when we add a new node?
I every level of the tree will be fully occupied
II the tree does not grow a new level
III the root contains the smallest element
(Multiple Choice)
4.8/5
(35)
Consider the following binary search tree:
Which of the following sequences correctly represents preorder traversal of this tree?

(Multiple Choice)
4.7/5
(32)
Consider the following tree diagram:
Which of the following nodes are parent nodes?

(Multiple Choice)
4.9/5
(33)
If both of the child references of a binary tree node are non-null, it follows that the node must be ____.
(Multiple Choice)
4.8/5
(42)
The nodes in our binary search tree implement the Comparable interface. Which tree operations benefit from this design decision?
I add
II search
III delete
(Multiple Choice)
4.8/5
(41)
The height of a tree can be obtained by recursively computing the heights of its subtrees, while keeping track of the height of the deepest subtree. Given the Node class discussed in section 17.1 (partially shown below), select an expression to complete the recursive method height, which is designed to return the height of the tree rooted at a node. class Node
{
Public Object data;
Public List<Node> children;
) . .
Public int height()
{
Int maxChildHeight = 0;
For (Node child : children)
{
Int childHeight = child.height();
If (childHeight > maxChildHeight)
MaxChildHeight = childHeight;
}
Return _________________;
}
}
(Multiple Choice)
4.9/5
(29)
Consider the following Huffman encoding tree:
The letter H will be encoded as ____.

(Multiple Choice)
4.9/5
(38)
If the child references of a binary tree node are both null, the node is ____.
(Multiple Choice)
4.9/5
(44)
Consider the following tree diagram:
Which arithmetic expression is represented by this tree?

(Multiple Choice)
4.8/5
(37)
A binary tree with 260 nodes has a height of approximately ____.
(Multiple Choice)
4.9/5
(37)
Given the BinarySearchTree class discussed in section 17.3 (partially shown below), select a sequence of statements to complete the recursive postorder method. The method performs a postorder traversal of the binary search tree rooted at node n. public class BinarySearchTree
{
Private Node root;
Public BinarySearchTree() {...}
Public void postorderTraversal()
{
Postorder(root);
}
Private static void postorder(Node n)
{
If (n != null)
{
____________________
____________________
____________________
}
}
) . .
}
(Multiple Choice)
4.8/5
(31)
Consider the following tree diagram:
Which of the following statements is NOT correct?

(Multiple Choice)
4.8/5
(43)
Given the BinaryTree class discussed in section 17.2 (partially shown below), select an expression to complete the static recursive helper method countLeaves, which returns the number of leaf nodes in the binary tree rooted at node n. public class BinaryTree
{
Private Node root;
Public BinaryTree()
{
Root = null;
}
Public BinaryTree(Object rootData, BinaryTree left, BinaryTree right)
{
Root = new Node();
Root.data = rootData;
Root.left = left.root;
Root.right = right.root;
}
Class Node
{
Public Object data;
Public Node left;
Public Node right;
}
Public int countLeaves()
{
Return countLeaves(root);
}
Public static int countLeaves (Node n)
{
If (n == null)
{
Return 0;
}
Else if (_____________________)
{
Return 1;
}
Else
{
Return countLeaves(n.left) + countLeaves(n.right);
}
}
}
(Multiple Choice)
4.8/5
(33)
Showing 1 - 20 of 110
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)