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

  Creating a single table to hold the information

Think about a typical sales invoice that would include the given information. Create a single table to hold all of the information needed to store an invoice including this information.

  Explain how to determine line in o-n lg n time

Explain how to determine such a line in O(n lg n) time. Provide the O(n^2 lg n)-time algorithm to pair Ghostbusters with ghosts in such a way that no streams cross.

  Find running time of heap sort input sorted-ascending order

Determine the running time of Heap Sort if input is sorted in ascending order. Determine the running time of Heap Sort if input is sorted in descending order.

  Create an algorithm to produce list of customers

Create an algorithm to produce list of customers from Glad Rags Clothing Company's customer master file. Each record on customer master file contains the customer's number

  Hardware platform of the target embedded systems

An embedded system is a computer system performing dedicated functions within a larger mechanical or electrical system. Embedded systems range from portable devices such as Google Glasses, to large stationary installations like traffic lights, fa..

  Entity relationship diagrams

Discuss why are Entity Relationship Diagrams an important initial stage in developing databases? Who would be the initial parties interacting to develop the ERDs?

  Threat model to describe risk of attack vector

Construct a simple threat model that describes the risk this represents: attacker(s), attack vector, vulnerability, assets, and likelihood of occurrence, likely impact, and plausible mitigations.

  Define file type

Define File Type and provide some of the important information to know about it and where do file types come from?

  Describe why algorithm runs in on time

Assume you have the array A of n items, and you want to find k items in A closest to the median of A. Describe why your algorithm runs in O(n) time.

  Perform page trace analysis by fifo page removal algorithm

Using the FIFO page removal algorithm, do a page trace analysis indicating page faults with asterisks (*). Then compute the failure and success ratios.

  Create ef?cient algorithm to fnd redundancies

Fnd the redundancies m1, · · · , mn that are within the available budget and that maximize probability that system works correctly. Create an ef?cient algorithm.

  Data structures for a single algorithm

Data structures for a single algorithm

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