Chapter 25 - A Binary Search Implementation

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

What is the worst-case performance of the getEntry method in a full binary search tree with linked nodes?

O(log n)

What is the worst-case performance of the remove method in a full binary search tree with linked nodes?

O(log n)

Write a pseudo code algorithm for searching a binary search tree.

If(binary search tree is empty) return false else if(object being searched for is equal to the root of the tree) return true else if(object being searched for is less than the root of the tree) recursively call the search algorithm on the left subtree else recursively call the search algorithm on the right subtree.

Given a binary search tree with n nodes and height h, what is the maximum number of comparisons that each operation requires for the method add?

O(h)

Given a binary search tree with n nodes and height h, what is the maximum number of comparisons that each operation requires for the method remove?

O(h)

Given a binary search tree with nnodes and height h, what is the maximum number of comparisons that each operation requires for the method getEntry?

O(h)

What is the worst-case performance of the addmethod in a full binary search tree with linked nodes?

O(log n)

What is the worst-case performance of the add method in a binary search tree with linked nodes?

O(n)

What is the worst-case performance of the getEntry method in a binary search tree with linked nodes?

O(n)

What is the worst-case performance of the remove method in a binary search tree with linked nodes?

O(n)

Why can't the two setTreemethods that are inherited from BinaryTree be used in the class BinrarySearchTree?

One could create a tree that does not have the properties of a binary search tree

When adding an entry to a binary search tree, when does the search ends?

When the item is found, At a leaf if the entry is not already in the tree

Binary search trees are not an efficient choice for searching if the data tends to remain stable.

False

Every addition to a binary search tree adds a new root.

False

For best performance, when you add entries to a binary search tree, you should add them in sorted order.

False

How does the class BinarySearchTree handle the two setTreemethods that are inherited from BinaryTree?

They are overridden with methods that throw an exception if called

Searching a binary search tree is like performing a binary search of an array.

True

The shape of a binary search tree affects the efficiency of the simple recursive search algorithm.

True

When adding an entry to a binary search tree, the search ends at a leaf if the entry is not already in the tree.

True

You can create different binary search trees from the same data.

True

You can implement the ADT dictionary using a binary search tree.

True

When you add entries to a binary search tree, if possible, you should not add them in sorted order. Explain.

adding them in sorted, or nearly sorted order produces a tree with a very large height yielding an O(n) performance on the add, remove and getEntry operations. if the data is entered in a ore random fashion, the height will be smaller, approaching the optimum performance of O(log n) for a full search tree.

In the interface SearchTreeInterface, the method getEntryreturns an object in the tree that matches the given entry according to the entry's _____ method.

compareTo

In a binary search tree, the getInorderIteratorinherited from the class BinaryTree sorts data

in ascending order

Every addition to a binary search tree adds a new

leaf

If a node x is the inorder predecessor of node y then node x must appear in y's _____ subtree.

left

The data in a node's _____ subtree are less than the data in a node's _____ subtree.

left, right

In the interface SearchTreeInterface, what does the method addreturn if the object being added doesn't exist?

null

In the interface SearchTreeInterface, what does the method getEntryreturn if the object being sought doesn't exist?

null

In the interface SearchTreeInterface, what does the method removereturn if the object being sought doesn't exist?

null

If a node x is the inorder successor of node y then node x must appear in y's _____ subtree.

right

In the interface SearchTreeInterface, what does the method addreturn if the object being added already exists in the tree?

the existing entry that matched the parameter

The inorder predecessor of a node N is

the largest entry in the N's left subtree

The inorder successor of a node N is

the smallest entry in the N's right subtree

The smallest entry in a node N's left subtree is

the subtree's leftmost node

The smallest entry in a node N's right subtree is

the subtree's leftmost node

The largest entry in a node N's left subtree is

the subtree's rightmost node

The largest entry in a node N's right subtree is

the subtree's rightmost node

How do you remove a node that is a leaf in a binary search tree?

you locate the parent node ans set the appropritate child reference in the parent node to null.


Conjuntos de estudio relacionados

SKILLS - Ch. 41 - Dressings/Bandages...

View Set

MSK - Development Part I - (Kuhn) - JCN

View Set

Elsevier Adaptive Quizzing Fundamentals Fall Semester 226

View Set

COSC: 11.4 Methods: Common errors

View Set

Finish editing....Care of Patients with Diabetes Mellitus

View Set