< Free Open Study > |
Which of these formulas gives the maximum total number of nodes in a tree that has N levels? (Remember that the root is Level 0.)
N^{2} - 1
2^{N}
2^{N} - 1
2^{N+}^{1}
Which of these formulas gives the maximum number of nodes in the Nth level of a binary tree?
N^{2}
2^{N}
2^{N}^{+1}
2^{N} - 1
How many ancestors does a node in the Nth level of a binary search tree have?
How many different binary trees can be made from three nodes that contain the key values 1, 2, and 3?
How many different binary search trees can be made from three nodes that contain the key values 1, 2, and 3?
Draw all possible binary trees that have four leaves where all nonleaf nodes have two children.
The TreeType class used a queue as an auxiliary storage structure for iterating through the elements in the tree. Discuss the relative merits of using a dynamically allocated array-based queue versus a dynamically allocated linked queue.
Answer the questions in Exercises 8-10 independently, using the following tree.
What are the ancestors of node P?
What are the descendants of node K?
What is the maximum possible number of nodes in the tree at the level of node W?
What is the maximum possible number of nodes in the tree at the level of node N?
Insert node O. How many nodes would be in the tree if it were completely full down to and including the level of node O?
Show what the tree would look like after each of the following changes. (Use the original tree to answer each part.)
Add node C.
Add node Z.
Add node X.
Delete node M.
Delete node Q.
Delete node R.
Show the order in which the nodes in the tree are processed by
an inorder traversal of the tree.
a postorder traversal of the tree.
a preorder traversal of the tree.
Draw the binary search tree whose elements are inserted in the following order:
50 72 96 94 107 26 12 11 9 2 10 25 51 16 17 95
Exercises 12-16 use the following tree.
What is the height of the tree?
What nodes are on Level 3?
Which levels have the maximum number of nodes that they could contain?
What is the maximum height of a binary search tree containing these nodes? Draw such a tree.
What is the minimum height of a binary search tree containing these nodes? Draw such a tree.
Trace the path that would be followed in searching for a node containing 61.
Trace the path that would be followed in searching for a node containing 28.
Show the order in which the nodes in the tree are processed by
an inorder traversal of the tree.
a postorder traversal of the tree.
a preorder traversal of the tree.
Show how the tree would look after the deletion of 29, 59, and 47.
Show how the (original) tree would look after the insertion of nodes containing 63, 77, 76, 48, 9, and 10 (in that order).
True or false?
Invoking the delete function in this chapter might create a tree with more levels than the original tree had.
A preorder traversal processes the nodes in a tree in the exact reverse order that a postorder traversal processes them.
An inorder traversal always processes the elements of a tree in the same order, regardless of the order in which the elements were inserted.
A preorder traversal always processes the elements of a tree in the same order, regardless of the order in which the elements were inserted.
If you wanted to traverse a tree, writing all the elements to a file, and later (the next time you ran the program) rebuild the tree by reading and inserting, would an inorder traversal be appropriate? Why or why not?
One hundred integer elements are chosen at random and inserted into a sorted linked list and a binary search tree. Describe the efficiency of searching for an element in each structure, in terms of Big-O notation.
One hundred integer elements are inserted in order, from smallest to largest, into a sorted linked list and a binary search tree. Describe the efficiency of searching for an element in each structure, in terms of Big-O notation.
The key of each node in a binary search tree is a short character string.
Show how such a tree would look after the following words were inserted (in the order indicated):
monkey canary donkey deer zebra yak walrus vulture penguin quail
Show how the tree would look if the same words were inserted in this order:
quail walrus donkey deer monkey vulture yak penguin zebra canary
Show how the tree would look if the same words were inserted in this order:
zebra yak walrus vulture quail penguin monkey donkey deer canary
Write a function called PtrToSuccessor that finds a node with the smallest key value in a tree, unlinks it from the tree, and returns a pointer to the unlinked node.
Modify the DeleteNode function so that it uses the immediate successor (rather than the predecessor) of the value to be deleted in the case of deleting a node with two children. You should call the function PtrToSuccessor that you wrote in Exercise 21.
Use the Three-Question Method to verify the recursive function Insert.
Use the Three-Question Method to verify the recursive function Delete.
Write IsFull and IsEmpty for the iterative version of class TreeType.
Add a TreeType member function Ancestors that prints the ancestors of a given node whose info member contains value. Do not print value.
Write the declaration.
Write the iterative implementation.
Write a recursive version of the function Ancestors described in Exercise 26.
Write a recursive version of Ancestors (see Exercise 27) that prints out the ancestors in reverse order (first the parent, then the grandparent, and so on).
Add a Boolean member function IsBST to the class TreeType that determines whether a binary tree is a binary search tree.
Write the declaration of the function IsBST. Include adequate comments.
Write a recursive implementation of this function.
Extend the Binary Search Tree ADT to include the member function LeafCount that returns the number of leaf nodes in the tree.
Extend the Binary Search Tree ADT to include the member function SingleParentCount that returns the number of nodes in the tree that have only one child.
Write a client function that returns a count of the nodes that contain a value less than the parameter value.
Extend the Binary Search Tree ADT to include a Boolean function SimilarTrees that receives pointers to two binary trees and determines whether the shapes of the trees are the same. (The nodes do not have to contain the same values, but each node must have the same number of children.)
Write the declaration of the function SimilarTrees as a TreeType member function. Include adequate comments.
Write the body of the function SimilarTrees.
The TreeType member function MirrorImage creates and returns a mirror image of the tree.
Write the declaration of the function MirrorImage. Include adequate comments.
Write the body of the function MirrorImage.
Can the binary tree returned from this function be used for binary searching? If so, how?
Write a client function MakeTree that creates a binary search tree from the elements in a sorted list of integers. You cannot traverse the list inserting the elements in order, as that would produce a tree that has N levels. You must create a tree with at most log_{2}N + 1 levels.
Write a client Boolean function MatchingItems that determines whether a binary search tree and a sequential list contain the same values.
Examine the following binary search tree and answer the questions in Exercises 37-40. The numbers on the nodes are labels so that we can talk about the nodes; they are not key values within the nodes.
If an item is to be inserted whose key value is less than the key value in node 1 but greater than the key value in node 5, where would it be inserted?
If node 1 is to be deleted, the value in which node could be used to replace it?
4 2 7 5 1 6 8 3 is a traversal of the tree in which order?
1 2 4 5 7 3 6 8 is a traversal of the tree in which order?
In Chapter 6, we discussed how to store a linked list in an array of nodes using index values as "pointers" and managing our list of free nodes. We can use these same techniques to store the nodes of a binary search tree in an array, rather than using dynamic storage allocation. Free space is linked through the left member.
Show how the array would look after these elements had been inserted in this order:
Q L W F M R N S
Be sure to fill in all the spaces. If you do not know the contents of a space, use "?".
Show the contents of the array after "B" has been inserted and "R" has been deleted.
Which of the following trees are complete?
Which of the following trees are full?
The elements in a binary tree are to be stored in an array, as described in the chapter. Each element is a nonnegative int value.
What value can you use as the dummy value, if the binary tree is not complete?
Show the contents of the array, given the tree illustrated below.
The elements in a complete binary tree are to be stored in an array, as described in the chapter. Each element is a nonnegative int value. Show the contents of the array, given the tree illustrated below.
Given the array pictured below, draw the binary tree that can be created from its elements. The elements are arranged in the array as discussed in the chapter.
A binary tree is stored in an array called treeNodes, which is indexed from 0 to 99, as described in the chapter. The tree contains 85 elements. Mark each of the following statements as True or False, and correct any false statements.
treeNodes[42] is a leaf node.
treeNodes[41] has only one child.
The right child of treeNodes[12] is treeNodes [25].
The subtree rooted at treeNodes[7] is a full binary tree with four levels.
The tree has seven levels that are full, and one additional level that contains some elements.
Implement the Binary Search Tree ADT as a template class.
< Free Open Study > |
Converted from CHM to HTML with chm2web Pro 2.85 (unicode) |