Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Data Structure Expert

Part I: written exercises:

1. Begin with the following binary search tree, draw the BST that results after the operation or sequence of operations is performed. (All questions are independent and each question starts from the BST as following)

260_img1.png

a. Insert 7

b. Insert 7, 1, 55, 29, and 19

c. Delete 8

d. Delete 8, 37, and 62

e. Insert 7, delete 8, insert 59, delete 60, insert 92, delete 50.

f.  Display the output produced by an inorder traversal

g. Display the output produced by a preorder traversal

h. Display the output produced by a postorder traversal.

2. For the arithmetic expressions below, draw a binary tree that represents the expression, and then use tree traversals to find the equivalent prefix and postfix expressions.

a. (A-B)-C

b. A/ (B-(C-(D-(E-F))))

c. ((A*(B+C))/(D-(E+F)))*(G/(H/(I*J)))

3. Construct the Huffman code for the Java keyword and weights given in the following table.

Words

Weight

int

0.30

main

0.30

while

0.05

if

0.20

for

0.15

Part II: programming exercise

Start with the tree.java program (Listing 8.1) and modify it to create a binary tree from a string of letters (like A, B, and so on) entered by the user. Each letter will be displayed in its own node. Construct the tree so that all the nodes that contain letters are leaves. Parent nodes can contain some non-letter symbol like +. Make sure that every parent node has exactly two children.

Don't worry if the tree is unbalanced. Note that this will not be a search tree; there's no quick way to find a given node. You may end up with something like this:

519_img2.png

One way to begin is by making an array of trees. (A group of unconnected trees is called a forest.) Take each letter typed by the user and put it in a node. Take each of these nodes and put it in a tree, where it will be the root. Now put all these one-node trees in the array. Start by making a new tree with + at the root and two of the one-node trees as its children. Then keep adding one-node trees from the array to this larger tree. Don't worry if it's an unbalanced tree. You can actually store this intermediate tree in the array by writing over a cell whose contents have already been added to the tree.

The routines find(), insert(), and delete(), which apply only to search trees, can be deleted. Keep the displayTree() method and the traversals because they will work on any binary tree.

Data Structure, Computer Science

  • Category:- Data Structure
  • Reference No.:- M91381113
  • Price:- $30

Guranteed 24 Hours Delivery, In Price:- $30

Have any Question?


Related Questions in Data Structure

Problem regarding the management program

Problem: Looks like its just adding a save and load feature to the same file you sent me for python 3.5 Until now, you have had to leave your team management program running on your computer indefinitely since you did no ...

Data Communication Delivering Information anywhere

Topic: Data Communication Delivering Information anywhere. Write a 9-12 pages paper in which you: Present an overview of the origin and history of the concept. Describe the current use of and attitude toward the concept. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As