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

  Devise ef?cient algorithm for computing probability

Given the probabilities r1, · · · , rn, the costs c1, · · · , cn, and the budget B, ?nd the redundancies m1, · · · , mn that are within the available budget and that maximize the probability that the system works correctly. Devise an ef?cient algo..

  Create algorithm to prepare daily hotel charge report

Create the algorithm to prepare the daily hotel charge report. Input consists of series of records which contain a room number, customer name, cost of the room, and cost of meals charged to the room.

  Encryption feistel cipher and decryption algorithm

If this is psudocode for encryption feistel cipher determine decryption algorithm?Output: ciphertext = (left[16], right[16]) Explain pseudo-code of corresponding decryption algorithm for this cipher.

  Create binary tree based on names

The Binary Tree is one of best ways to organize information when you require fast access. For this project, we will organize a list of names and perform many operations on those names.

  Taxonomy tree as its input and returns a string

Designing an algorithm that takes a taxonomy tree as its input and returns a string that contains the type of "item" (animal, plant, etc) that was found after traversing the tree.

  Singly linked list

Singly Linked List (SLL)Introduce a SLL class with the following functions. Please also introduce a main function that will invoke and verify whether the functions are implemented correctly

  Why there are no forward nontree edges

Explain why there are no forward nontree edges with respect to a BFS (breadth-first search) tree constructed for a direct graph.

  Efficient algorithm to achieve goal using few base stations

Certain points along the road, so that every house is within four miles of one of the base stations. Give an efficient algorithm that achieves this goal using as few base stations as possible.

  Create algorithm to read file of employee records

Create the algorithm which will read a file of employee records and produce the weekly report of gross earnings for those employees.

  Java program to find largest and smallest numbers

Create a Java program that will search a text document of strings representing numbers of type int and will write the largest and the smallest numbers to screen.

  Include methods to set and get values for each data field

Design a class named MagazineSubscription that has fields for a subscriber's name, the magazine name, and number of months remaining in the subscription. Include methods to set and get the values for each data field.

  The number of operations executed by algorithms

The number of operations executed by algorithms A andB is 8nlogn and 2n 2 , respectively. Determine n 0  such that Ais better thanB for n ? n 0 .

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