Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Haskell program (.hs). Thank You. Problem description: A directed graph can be implemented as a list, whose elements are pairs of nodes. Assume

Please use Haskell program (.hs). Thank You.

image text in transcribedimage text in transcribedimage text in transcribed

Problem description: A directed graph can be implemented as a list, whose elements are pairs of nodes. Assume the nodes are integers. In Haskell, you can define a graph as follows: type Node = Integer type Edge = (Integer, Integer) type Graph = [Edge] type Path = [Node] g :: Graph g = [ (1, 2), (1, 3), (2, 3), (2, 4), (3, 4) ] h :: Graph h = [ (1, 2), (1, 3), (2, 1), (3, 2), (4,4) ] 3. Write a function named detach that takes a node N and a graph G and returns the graph formed by removing N from G. For example, detach 3 g => [(1, 2), (2, 4)]. 4. Write a function named paths that accepts two nodes V1 and V2 (and a graph G) and returns a list of all possible cycle-free paths from V1 to V2. For example, paths 2 2 g => [[2]], paths 3 2 g => [], paths 1 4 g => [[1, 2, 3, 4], [1, 2, 4], [1, 3, 4]]. Problem description: A directed graph can be implemented as a list, whose elements are pairs of nodes. Assume the nodes are integers. In Haskell, you can define a graph as follows: type Node = Integer type Edge = (Integer, Integer) type Graph = [Edge] type Path = [Node] g :: Graph g = [ (1, 2), (1, 3), (2, 3), (2, 4), (3, 4) ] h :: Graph h = [ (1, 2), (1, 3), (2, 1), (3, 2), (4,4) ] 3. Write a function named detach that takes a node N and a graph G and returns the graph formed by removing N from G. For example, detach 3 g => [(1, 2), (2, 4)]. 4. Write a function named paths that accepts two nodes V1 and V2 (and a graph G) and returns a list of all possible cycle-free paths from V1 to V2. For example, paths 2 2 g => [[2]], paths 3 2 g => [], paths 1 4 g => [[1, 2, 3, 4], [1, 2, 4], [1, 3, 4]]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 15th International Conference Dexa 2004 Zaragoza Spain August 30 September 3 2004 Proceedings Lncs 3180

Authors: Fernando Galindo ,Makoto Takizawa ,Roland Traunmuller

2004th Edition

3540229361, 978-3540229360

More Books

Students also viewed these Databases questions

Question

State the uses of job description.

Answered: 1 week ago

Question

Explain in detail the different methods of performance appraisal .

Answered: 1 week ago