Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
bartleby

Concept explainers

Question
Book Icon
Chapter 15, Problem 1P

(a)

Program Plan Intro

To describe a dynamic-programming approach for finding longest simple path in directed acyclic graph and also give the running time of the algorithm.

(a)

Expert Solution
Check Mark

Explanation of Solution

Given Information:

The shortest closed tour of the graph with length approximately is 24.89. The directed acyclic graph is shown below-

Introduction to Algorithms, Chapter 15, Problem 1P , additional homework tip  1

Explanation:

The dynamic-approach used to find the longest length simple path consider the graph G and vertices as V. The longest simple path must go through some edge of weight s or t . The algorithms to compute the longest weight path is longest(G,s,t)=1+max(longest(G,s',t)) .

The base condition for the algorithm is s=t and the initial length is 0.It can see that it consider this many possible sub-problems by taking |G| and complete graph on vertices V .

The algorithm to compute longest simple path in a directed acyclic graph is given below-

LONG-PATH(G,u,s,t,len)

If t==s then

set len(s)=0 .

return ( len,u )

else if u[s]==NULL then

Return (len,u).

else

for each adjacent vertex uG of s.

Check the distance after adding new vertex i.

if w(s,u)+len[u]len[s] then

  len[s]=w(s,u)+len[u] .

  u[s]=t .

end if.

end for.

end if.

return ( len,u ).

end.

In above algorithm, loop of for is used to determine the longest path and the longest path visit all vertex by checking all adjacent vertex.

The time taken by the algorithm is depends upon the number of vertex visited and the number of edges in the longest simple path. Suppose V represent the number of vertex used in the computing the longest simple path and E represent the number of edges then total running time of the algorithm is equals to O(V+E) .

(b)

Program Plan Intro

To describe a dynamic-programming approach for finding longest simple path in directed acyclic graph and also give the running time of the algorithm.

(b)

Expert Solution
Check Mark

Explanation of Solution

Given Information:

The shortest closed tour of the graph with length approximately is 25.58. The directed acyclic graph is shown below-

Introduction to Algorithms, Chapter 15, Problem 1P , additional homework tip  2

Explanation:

The longest simple path must go through some edge of weight s . The base condition for the algorithm is s=t and the initial length is 0.It can see that it consider this many possible sub-problems by taking |G| and complete graph on vertices V .

The algorithm to compute longest simple path in a directed acyclic graph is given below-

LONG-PATH(G,u,s,t,len)

If t==s then

set len(s)=0 .

return ( len,u )

else if u[s]==NULL then

Return (len,u).

else

for each adjacent vertex uG of s.

Check the distance after adding new vertex i.

if w(s,u)+len[u]len[s] then

  len[s]=w(s,u)+len[u] .

  u[s]=t .

end if.

end for.

end if.

return ( len,u ).

end.

The time taken by the algorithm is depends upon the number of vertex visited and the number of edges in the longest simple path. Suppose V represent the number of vertex used in the computing the longest simple path and E represent the number of edges then total running time of the algorithm is equals to O(V+E) .

The above algorithm taken consideration of the nodes and generates the output according to the number of nodes in the graph so the longest length is computed by longest(G,s,t)=1+max(longest(G,s',t)) .

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
A cylinder of diameter 10 cm rotates concentrically inside another hollow cylinder of inner diameter 10.1 cm. Both cylinders are 20 cm long and stand with their axis vertical. The annular space is filled with oil. If a torque of 100 kg cm is required to rotate the inner cylinder at 100 rpm, determine the viscosity of oil. Ans. μ= 29.82poise
Make the following game user friendly with GUI, with some simple graphics The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units.  Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return isWall; } public void setWall(boolean isWall) { this.isWall = isWall; } @Override public String toString() {…
Please original work What are four of the goals of information lifecycle management think they are most important to data warehousing, Why do you feel this way, how dashboards can be used in the process, and provide a real life example for each. Please cite in text references and add weblinks
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education