Input: a list of pairs, L and a list S. Interpreting L as a binary relation over the set S, Reflexive-Closure should return the reflexive closure of L.
Implement the following Racket functions:
Reflexive-Closure
Input: a list of pairs, L and a list S. Interpreting L as a binary relation over the set S, Reflexive-Closure should return the reflexive closure of L.
In mathematics, the reflexive closure of a binary relation R on a set X is the smallest reflexive relation on X that contains R. (https://en.wikipedia.org/wiki/Reflexive_closure)
Examples:
(Reflexive-Closure '((a a) (b b) (c c)) '(a b c))
---> '((a a) (b b) (c c))
(Reflexive-Closure '((a a) (b b)) '(a b c))
---> '((a a) (b b) (c c))
(Reflexive-Closure '((a a) (a b) (b b) (b c)) '(a b c))
---> ((a a) (a b) (b b) (b c) (c c))
(Reflexive? '() '(a b c))
---> '((a a) (b b) (c c))
You must use recursion, and not iteration. You may not use side-effects (e.g. set!).
Trending now
This is a popular solution!
Step by step
Solved in 2 steps