Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Working on a Java project to dictionary as a binary tree. 1.Data structure (0.1points) A word in a dictionary will keep the key (the defined

Working on a Java project to dictionary as a binary tree.

1.Data structure (0.1points)A word in a dictionary will keep the key (the defined word)and a definition (another string).For each node we will keep a link to the left subtree containing the words before the current word and a link to the right subtree containing the words after the current word.

2. Test and initialize (0.1 points) I want to do a method that will initialize a binary tree with15 terms from the textbook. Provide correct names and definitions for the test data.

3. Print a binary tree (0.1 points)I want to do a method that will print a binary tree in the following format.

LEFT NODE

ROOT NODE

RIGHT NODE

For instance a valid tree is (ignore the bullets):

A

oB

C

D

E

oF

G

Use a recursive function that will receive the number of spaces before a node (4 spaces for each level), and a node. The function will do nothing if the node is null. If the node has a left subtree, call it recursively to print the subtree, but with more spaces. Then print the spaces and the node key. Then print recursively the right subtree with more spaces. Test the method by showing the tree after each operation performed in step 2.

3. Find a word in the dictionary (0.1 points)Createmethod that will receive a word and return the definition if the word is in dictionary or null otherwise.Test the method with two words from dictionary and two not in the dictionary.

4. Insert a word (0.1 points)Createmethod that will receive a wordand its definition. If the word is in dictionary, update the definition. If not, add the word to the dictionary. Test the method with two refined definitions and two new definitions. Print the dictionary after each operation.

5. Check if leaf, single leaf and two leaves(0.1 points)Create three methods that will check if a word is a leaf, has a single child or has 2 children.Returns true if the property holds, otherwise false. Check the method with various words: 2 leafs, 2 single child, 2 twochildrenand 2 not in the dictionary.Print the dictionary after each operation.

6. Delete a leaf node (0.1 points)I want to do a method that will receive a word and if the word is a leaf delete the node from the dictionary.Check the method with various words: 2 leafs, 2 single child, 2 twochildrenand 2 not in the dictionary.Print the dictionary after each operation.

One way to implement is: make a method that will receive a subtree root node and a key to delete. If the node is a leaf and has the same key remove the node from the tree and return the resulted subtree. The caller must link the subtree.

7.Delete a node with a child(0.1points)Createa method that will receivea word and if the word has a single child delete the node from the dictionary.Check the method with various words: 2 leafs, 2 single child, 2 twochildrenand 2 not in the dictionary.Print the dictionary after each operation.

8.Delete a node with two children(0.1points)Createa method that will receivea word and if the word has two children delete the node from the dictionary.Check the method with various words: 2 leafs, 2 single child, 2 twochildrenand 2 not in the dictionary.Print the dictionary after each operation.

9.Delete any node(0.1points)Combine the previous 3 delete methods to create one method to delete any node.Check the method with various words: 2 leafs, 2 single child, 2 twochildrenand 2 not in the dictionary.Print the dictionary after each operation.

10. First and last word (0.1 points)Createa method that will return the first and the last wordfrom the dictionary. Check the methods.

11. Preorder(0.3 points)make a method that will traverse the tree in preorderand show the words in the console. Check the method.

12.Inorder(0.2 points)make a method that will traverse the tree ininorderand show the words in the console. Check the method.

13.Postorder(0.3 points)make a method that will traverse the tree inpostorderand show the words in the console. Check the method.

14. Height of the tree (0.1 points)Create a method that will compute the height tree. Check the method.

15. Find the word with longest definition (0.1 points).Create a method that will compute the word with the longest definition. Check the method.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Programming questions