Chapter 25 Binary Search Trees

Ace your homework & exams now with 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

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 ______.

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

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 __________ (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

The ________ is to visit 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

A Huffman tree is constructed using the ____________ algorithm.

greedy

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

height

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

A _____ of a path is the number of the edges in the path

length

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

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


Related study sets

Google Analytics Certification Exam

View Set

Set Theory & Relational Theory for Databases

View Set