Computer Science Homework Solutions
Problem
#6578

Problems about binary search tree in Java.

Questions:

a. Consider the following binary search tree: (Please see the figure in attached problem file)
i. What tree results after you insert the nodes 44, 48, 32, 36, 38, and 49 in that order? You only need to show the final result.
ii. Given the original tree, what tree results when you delete the node 43 and then node 50? (Note: there may be more than one correct answer, but please choose only one).

a. If you delete an item from a binary search tree and then immediately insert it back into the tree, will you always end up with the same tree? Briefly justify your answer.

b. Suppose that we have a set of unique numbers between 1 and 1000 in a binary search tree and want to search for the number 363. Which of the following sequences could not be the sequence of nodes examined? Only explain the invalid cases (no need to explain the others).
i. 2, 252, 401, 398, 330, 344, 397, 363
ii. 924, 220, 911, 244, 898, 258, 362, 363
iii. 925, 202, 911, 240, 912, 245, 363
iv. 2, 399, 387, 219, 266, 382, 381, 278, 363
v. 935, 278, 347, 621, 299, 392, 358, 363

c.Write the following method which tests if a BinaryTree is a binary search tree. Assume this method exists in the BinaryTree class. Note: Empty binary trees should also be considered to be binary search trees.
public boolean isBinarySearchTree()
// post: returns true iff this is a binary search tree



Attached file(s):
Attachments
problem1.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

problem1.doc
Consider the following binary search tree:

INCLUDEPICTURE \d "Image1.jpg"

What tree results after you insert the nodes 44, 48, 32, 36, 38, and 49
in that order? You only need to show the final result.

Given the original tree, what tree results when you delete the node 43
and then node 50? (Note: there may be more than one correct answer, but
please choose only one).

If you delete an item from a binary search tree and then immediately
insert it back into the tree, will you always end up with the same tree?
Briefly justify your answer.

Suppose that we have a set of unique numbers between 1 and 1000 in a
binary search tree and want to search for the number 363. Which of the
following sequences could not be the sequence of nodes examined? Only
explain the invalid cases (no need to explain the others).

2, 252, 401, 398, 330, 344, 397, 363

924, 220, 911, 244, 898, 258, 362, 363

925, 202, 911, 240, 912, 245, 363

2, 399, 387, 219, 266, 382, 381, 278, 363

935, 278, 347, 621, 299, 392, 358, 363

c.Write the following method which tests if a BinaryTree is a binary
search tree. Assume this method exists in the BinaryTree class. Note:
Empty binary trees should also be considered to be binary search trees.

public boolean isBinarySearchTree()

// post: returns true iff this is a binary search tree

43

30

21

37

50

67

33

73
Solution
What is this?
By OTA - Overall OTA Rating
Huanhuan Liang, MSc - 4.8/5
Purchase Cost Now
$2.19 CAD
Included in Download
  • Plain text response
  • Attached file(s):
    • answer.doc
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • A problem about binary trees in java - A problem about binary trees in java. Please see attachment. The original course website where the problem comes from is here, I think it will be helpful if you take a look at it first: www.student.ma ...
  • Algorithm Problem - Argue briefly that to test whether a given n-element permutation can be sorted by an n-input comparison network, it suffices to test the network on n—1 sequences of 0’s and 1’s.
  • Web page - Hail Sequences - Please see the attached file.
  • Web Site Structures - Describe Web site structures and the purpose of each structure.
  • SQL Indexes and Sequences - What are sequences and indexes in database tables? When to use sequence and when to use index?
Browse