Given n strings, each composed of the letters drawn from ‘a' to ‘z', determine whether the n strings can be placed end-to-end in a circle so that the last character of one string is equal to the first character of the next string (similar to the game of dominos). For example, the following four strings "duke" can be arranged in a circle as "esquire" "earl" "earl" "esquire" "lord" "lord" "duke" Note that the last character of "duke" matches the first character of "esquire". Requirements 1) Create a graph G that represents the given input of n strings. It may be useful to keep track of the in- and outdegrees of each vertex as edges are added to the graph. 2) Write a method that returns true if graph G satisfies the properties for an Eulerian tour. Otherwise, return false. Use Kosaraju's algorithm for finding the strongly connected components of a directed graph. 3) Write a method that returns a sequence of the n strings that forms an end-to-end circle (assuming G has an Eulerian tour).
Given n strings, each composed of the letters drawn from ‘a' to ‘z', determine whether the n strings can be placed end-to-end in a circle so that the last character of one string is equal to the first character of the next string (similar to the game of dominos). For example, the following four strings "duke" can be arranged in a circle as "esquire" "earl" "earl" "esquire" "lord" "lord" "duke" Note that the last character of "duke" matches the first character of "esquire". Requirements 1) Create a graph G that represents the given input of n strings. It may be useful to keep track of the in- and outdegrees of each vertex as edges are added to the graph. 2) Write a method that returns true if graph G satisfies the properties for an Eulerian tour. Otherwise, return false. Use Kosaraju's algorithm for finding the strongly connected components of a directed graph. 3) Write a method that returns a sequence of the n strings that forms an end-to-end circle (assuming G has an Eulerian tour).
Related questions
Question
![Given n strings, each composed of the letters drawn from ‘a' to ‘z', determine whether the n strings can be
placed end-to-end in a circle so that the last character of one string is equal to the first character of the next
string (similar to the game of dominos). For example, the following four strings
"duke"
can be arranged in a circle as
"esquire"
"earl"
"earl"
"esquire"
"lord"
"lord"
"duke"
Note that the last character of "duke" matches the first character of "esquire".
Requirements
1) Create a graph G that represents the given input of n strings. It may be useful to keep track of the in-
and outdegrees of each vertex as edges are added to the graph.
2) Write a method that returns true if graph G satisfies the properties for an Eulerian tour. Otherwise,
return false. Use Kosaraju's algorithm for finding the strongly connected components of a directed
graph.
3) Write a method that returns a sequence of the n strings that forms an end-to-end circle (assuming G has
an Eulerian tour).](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F92e5c125-0162-44af-aecb-b4cf9027a9d3%2F96eb6acb-d87a-44fc-8889-40f97af74b84%2F9z6bewj_processed.png&w=3840&q=75)
Transcribed Image Text:Given n strings, each composed of the letters drawn from ‘a' to ‘z', determine whether the n strings can be
placed end-to-end in a circle so that the last character of one string is equal to the first character of the next
string (similar to the game of dominos). For example, the following four strings
"duke"
can be arranged in a circle as
"esquire"
"earl"
"earl"
"esquire"
"lord"
"lord"
"duke"
Note that the last character of "duke" matches the first character of "esquire".
Requirements
1) Create a graph G that represents the given input of n strings. It may be useful to keep track of the in-
and outdegrees of each vertex as edges are added to the graph.
2) Write a method that returns true if graph G satisfies the properties for an Eulerian tour. Otherwise,
return false. Use Kosaraju's algorithm for finding the strongly connected components of a directed
graph.
3) Write a method that returns a sequence of the n strings that forms an end-to-end circle (assuming G has
an Eulerian tour).
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)