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
Given a graph that is a tree (connected and acyclic).  (I) Pick any vertex v.(II) Compute the shortest path from v to every other vertex. Let w be the vertex with the largest shortest path distance.(III) Compute the shortest path from w to every other vertex. Let x be the vertex with the largest shortest path distance. Consider the path p from w to x.   Which of the following are truea. p is the longest path in the graphb. p is the shortest path in the graphc. p can be calculated in time linear in the number of edges/vertices
Given a graph that is a tree (connected and acyclic). (1) Pick any vertex v. (II) Compute the shortest path from v to every other vertex. Let w be the vertex with the largest shortest path distance. (III) Compute the shortest path from w to every other vertex. Let x be the vertex with the largest shortest path distance. Consider the path p from w to x. Which of the following are true a. p is the longest path in the graph b. p is the shortest path in the graph c. p can be calculated in time linear in the number of edges/vertices a,c a,b a,b,c b.c
Given N cities represented as vertices V₁, V2, un on an undirected graph (i.e., each edge can be traversed in both directions). The graph is fully-connected where the edge eij connecting any two vertices vį and vj is the straight-line distance between these two cities. We want to search for the shortest path from v₁ (the source) to VN (the destination). ... Assume that all edges have different values, and €₁,7 has the largest value among the edges. That is, the source and destination have the largest straight-line distance. Compare the lists of explored vertices when we run the uniform-cost search and the A* search for this problem. Hint: The straight-line distance is the shortest path between any two cities. If you do not know how to start, try to run the algorithms by hand on some small cases first; but remember to make sure your graphs satisfy the conditions in the question.
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