Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Data Structure Expert

Two distinct words can be joined if one, two or three of the letters at the end of the first word are the same as the letters at the beginning of the second word, and only if the letter/letters are in the same order.

FOR EXAMPLE:

Appleand pleasantcan be joined to form appleasant.
Grilland lammacan be joined to form grillama.
Predicamentand tensioncan be joined to form predicamentatension.

A word-snake of lengthn is a sequence of n words that can be joined each to the next to form one long string. Write a Java program that prompts the user to enter the name of the data file whose first record is a positive integer n(n<30)followed by n lines each containing a single word. The words consist only of lower-case letters, and are at least 4 letters longand are in alphabetical order.

Treat the problem as a directed graph with n nodes, where nodes representwords, and an edge from node i to node jmeans that word i and word j can be joined. A word cannot be adjacent to itself, even a word like outshout. Your program should prompt the user to enter two words (in lower case) at the keyboard and then write to the screen a single line of output something like one of the following:

You entered a word that is not in the list.
(Stop the program if this happens.)

The words "apple" and "telephone" are not connected.
(Print this if there is no word-snake beginning with "apple" and ending with "telephone".)

The shortest snake that begins with "apple" and ends with "telephone" has length 52.
(Print this if "apple" is connected to "telephone", and the shortest path connecting them is of length 51. You do not have to give the words that make up the word-snake.)

You will need a method that determines whether two words can be joined or not. This is a directed graph, so word i may be adjacent to word j without word j being adjacent to word i. There are pairs of words (like chairand ironic) where each is adjacent to the other, but this rarely happens.

Sometimes words can be joined in more than 1 way, like "phenomenon" and "nonsense". These two words can be joined by the single letter ‘n' or by the substring"‘non". In such cases the only thing that matters is that they can be joined. As stated above, in this problem we do not allow a word to be joined to itself even if it begins and ends with the same letter(s), such as "chronic" or "sturdiest". However, we do allow a word to be connected to itself, i.e. a word-snake of length 3 or more may begin and end with the same word, as seen by the following word-snake of length 5.


Attachment:- Program-3-Original2.docx

Data Structure, Computer Science

  • Category:- Data Structure
  • Reference No.:- M9893533
  • Price:- $70

Priced at Now at $70, Verified Solution

Have any Question?


Related Questions in Data Structure

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. ...

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 ...

  • 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