Answered step by step
Verified Expert Solution
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.
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) ] 1. Write a function named nodes to get the list of nodes (increasing) of a graph. For example, nodes g => [1, 2, 3, 4]. 2. Write a function named adjacent that takes a node N and a graph G and returns a list of all nodes that are connected to N such that N is the source. For example, adjacent 2 g => [3, 4], adjacent 4 g => [] , adjacent 4 h => [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) ] 1. Write a function named nodes to get the list of nodes (increasing) of a graph. For example, nodes g => [1, 2, 3, 4]. 2. Write a function named adjacent that takes a node N and a graph G and returns a list of all nodes that are connected to N such that N is the source. For example, adjacent 2 g => [3, 4], adjacent 4 g => [] , adjacent 4 h => [4]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started