Chapter 25

¡Supera tus tareas y exámenes ahora con Quizwiz!

Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the postorder traversal of the elements?

12 21 92 45 4 3

Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the elements after inserting 2 into the tree?

3 2 4 45 21 12 92

Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the inorder traversal of the elements?

3 4 12 21 45 92

Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the elements after deleting 45 from the tree?

3 4 21 12 92

Suppose the keys 3, 4, 45, 21, 92, 12 are inserted into a BST in this order. What is the preorder traversal of the elements?

3 4 45 21 12 92

algorithm makes the choice that is optimal locally in the hope that this choice will lead to a globally optimal solution.

greedy algorithm

The _______ of a nonempty tree is the length of the path from the root node to its furthest leaf + 1.

height

of a nonempty tree is the length of the path from the root node to its furthest leaf. It is 0 if the tree contains a single node is 0. Conventionally, it is -1 for an empty tree.

height

traversal recursively visits the left subtree, visit the root, and then recursively visit the right subtree recursively.

inorder

The ________ is to visit the left subtree of the current node first, then the current node itself, and finally the right subtree of the current node.

inorder traversal

In the implementation of BST, which of the following are true? A. Node is defined as an inner class inside BST. B. Node is defined as a static inner class inside BST because it does not reference any instance data fields in BST. C. Node has a property named left that links to the left subtree and a property named right that links to the right subtree and a property named right D. BST contains a property named root. If tree is empty, root is null.

A. Node is defined as an inner class inside BST. B. Node is defined as a static inner class inside BST because it does not reference any instance data fields in BST. C. Node has a property named left that links to the left subtree and a property named right that links to the right subtree and a property named right D. BST contains a property named root. If tree is empty, root is null.

A Huffman tree is constructed using the ____________ algorithm.

greedy

Scheme for compressing data by using fewer bits to encode characters that occur more frequently. The codes for characters are constructed based on the occurrence of characters in the text using a binary tree

Huffman coding

The time complexity for deleing an element into a binary search tree is _______.

O(n)

The time complexity for inserting an element into a binary search tree is _______.

O(n)

The time complexity for searching an element in a binary search tree is _______. A. O(n) B. O(logn) C. O(nlogn) D. O(n^2)

O(n)

A new element is always inserted into a leaf node.

True

True or False? You can traverse the elements in a BST using a for-each loop.

True

A __________ (with no duplicate elements) has the property that for every node in the tree the value of any node in its left subtree is less than the value of the node and the value of any node in its right subtree is greater than the value of the node.

binary search tree

is a binary search tree with the property that for every node in the tree, the value of any node in its left subtree is less than the value of the node, and the value of any node in its right subtree is greater than the value of the node.

binary search tree

is a hierarchical structure. It either is empty or consists of an element, called the root, and two distinct binary trees, called the left subtree and right subtree, either or both of which may be empty.

binary tree

visits the nodes level by level starting from the root.

breadth-first

The _________ is to visit the nodes level by level. First visit the root, then all children of the root from left to right, then grandchildren of the root from left to right, and so on.

breadth-first traversal

The _______ of a node is the length of the path from the root to the node.

depth

length of the path from the root to the node.

depth

traversal visits the root, then its left subtree or its right subtree recursively in any order.

depth-first

An object that provides a uniform way of traversing the elements in a container, such as a set, a list, or a binary tree. You learned how to define and implement these classes for traversing the elements in a binary tree.

iterator

is a node without children.

leaf

The ________ of a path is the number of the edges in the path.

length

is the number of the edges in the path.

length

is the set of all nodes with the same depth.

level

traversal visits the left subtree, the right subtree recursively, and finally the root.

postorder

The _________ is to visit the left subtree of the current node first, then the right subtree of the current node, and finally the current node itself.

postorder traversal

traversal visits the root, then its left subtree and its right subtree recursively.

preorder

The _________ is to visit the current node first, then the left subtree of the current node, and finally the right subtree of the current node.

preorder traversal

is the starting node of the tree.

root

___ of a node is the node with the parent.

sibling

process of visiting each node in the tree exactly once.

tree traversal


Conjuntos de estudio relacionados

EAQs CH 36 Drugs Used to Treat Thyroid Disease

View Set

FM 245: Fashion Forecasting Midterm

View Set

Unit 10 Practice Quiz -------- Fluid Balance

View Set