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
D. S. Malik, Data Structures Using C++, 2nd Edition, 2010
Methods (Ch6) - Review 1. (The MyRoot method) Below is a manual implementation of the Math.sqrt() method in Java. There are two methods, method #1 which calculates the square root for positive integers, and method #2, which calculates the square root of positive doubles (also works for integers). public class SquareRoot { public static void main(String[] args) { } // implement a loop of your choice here // Method that calculates the square root of integer variables public static double myRoot(int number) { double root; root=number/2; double root old; do { root old root; root (root_old+number/root_old)/2; } while (Math.abs(root_old-root)>1.8E-6); return root; } // Method that calculates the square root of double variables public static double myRoot(double number) { double root; root number/2; double root_old; do { root old root; root (root_old+number/root_old)/2; while (Math.abs (root_old-root)>1.0E-6); return root; } } Program-it-Yourself: In the main method, create a program that…
I would like to know the main features about the following 3 key concepts:1. Backup Domain Controller (BDC)2. Access Control List (ACL)3. Dynamic Memory
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
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
Fundamentals of Information Systems
Computer Science
ISBN:9781305082168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Principles of Information Systems (MindTap Course...
Computer Science
ISBN:9781285867168
Author:Ralph Stair, George Reynolds
Publisher:Cengage Learning
Text book image
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:9781337508841
Author:Carey
Publisher:Cengage