Treat the problem as a directed graph with n nodes

Assignment Help Data Structure & Algorithms
Reference no: EM13314221

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

Reference no: EM13314221

Questions Cloud

Delete an existing product from the database : Utilise an include statement to refer to connection.php instead of the long version of the database connection code so that you can keep the database more secure. See Notes for more details.
What is the total force exerted on the air parcel : An air parcel with mass = 150 kg is traveling at 15 meters per second due east at 38 degrees North at an altitude of 5500 meters. What is the total force exerted on the air parcel
View a situation with the same ethical perspective : A member of one culture may not view a situation with the same ethical perspective as a member of another culture.
What value will he obtain for the acceleration : In a laboratory experiment, a Physics Major is given a stopwatch. a meterstick, and a simple pendulum, what value will he obtain for the acceleration due to gravity
Treat the problem as a directed graph with n nodes : 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.
Calculate the maximum magnitude of the velocity : An object is moving in simple harmonic motion with an amplitude of 16 cm and a frequency of 2.0 Hz.  Calculate the maximum magnitude of the velocity
What is the maximum stretch during the motion : A horizontal spring-mass system has low friction, spring stiffness 155 N/m, and mass 0.6 kg. What is the maximum stretch during the motion
How does human activity impact greenhouse : How does human activity impact greenhouse gases found in the atmosphere
Difficulties associated with allocating overhead costs : Discuss the difficulties associated with allocating overhead costs in the contemporary manufacturing environment and identify strategies that firms can adopt to help make their overhead allocations more accurate and reliable.

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd