Question

2. Design a deterministic algorithm to solve the following problem. input: A directed acyclic graph G...

2. Design a deterministic algorithm to solve the following problem.
input: A directed acyclic graph G = (V, E) stored using adjacency lists.
output: A Hamiltonian path, if such a path exists. Otherwise, return NONE.


Your algorithm must take O(|V| + |E|) time. You must describe your algorithm in plain English (no pseudocode) and you must explain why the running time of your algorithm is O(|V| + |E|). Maximum half a page

0 0
Add a comment Improve this question Transcribed image text
Answer #1

To find if there is a Hamiltonian path in a DAG(or directed acyclic graph), we will use the concept of topological sorting. In topological sorting we order the vertices of the graph in such a way that for all the directed edges xy present in the DAG, vertex 'x' comes before vertex 'y' in the ordering. Topological sort in DAG can be computed in O(|V| + |E|) time. Topological sort can be performed easily in O(|V| + |E|) by repeatedly computing indegrees of vertices. After performing the topological sort we just need to check that if there exists an edge between each of the consecutive vertices in the topological order(This can be done in O(|V| + |E|) time by amortized analysis). If it is so, then there exists a hamiltonian path else not.

Add a comment
Know the answer?
Add Answer to:
2. Design a deterministic algorithm to solve the following problem. input: A directed acyclic graph G...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT