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
Computer Science In a triangle graph, the spanning-tree-doubling approximation to the TSP (in the version described in class for finding a walk that touches every vertex at least once, without shortcuts) will always produce a four-edge walk, even for inputs where there is a shorter three-edge cycle.   Find weights for the edges of this graph for which the ratio of (solution found by the approximation)/(optimal solution) is as large as possible. What is this ratio for your weights?
(1) Like divide and conquer, dynamic programming (DP) solves problems by combiningsolutions to subproblems: true or false?_______; unlike divide and conquer, DPsubproblems are independent: true or false?_______.   (2) For a graph G=<V, E>, the total running time of BFS is ?(____); the total running timeof DFS is ?(____). If G is an undirected graph, ∑? ∈ ???????(?) = ; if G is adirected graph, ∑? ∈ ???????(?) = __________.   (3) Heap sort algorithm is stable or not? _____ , in-place or not? ______. Its worst case timecomplexity is ?(____). The height of a heap A[1..n] is ____.   (4) For a sorting algorithm for an array of n elements, in the worst case the number ofinversions is _______ , the average number of inversions is _______.Shell sort algorithm is stable or not? ______ , in-place or not? _______ .   (5) The worst case time complexity of BuildMaxHeap is ?(_______). The worst case timecomplexity of MaxHeapify is ?(______). The worst case time complexity of Heap-Extract-Max…
We recollect that Kruskal's Algorithm is used to find the minimum spanning tree in a weighted graph. Given a weighted undirected graph G = (V , E, W), with n vertices/nodes, the algorithm will first sort the edges in E according to their weights. It will then select (n-1) edges with smallest weights that do not form a cycle. (A cycle in a graph is a path along the edges of a graph that starts at a node and ends at the same node after visiting at least one other node and not traversing any of the edges more than once.) Use Kruskal's Algorithm to nd the weight of the minimum spanning tree for the following graph.
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