Sale!

Solved CSCI 301 Lab 4 (Racket Programming: Recursion and Set Operations)

$30.00 $18.00

Original Work ?

Download Details:

  • Name: Lab-4-xcjxqv.zip
  • Type: zip
  • Size: 64.97 KB

Category: Tags: , , You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal. Two sets
are equal if they contain exactly the same members, ignoring ordering (or in other words, two sets
are equal if they are a subset of each other). For example
(set-equal? ‘(1 (2 3)) ‘((3 2) 1)) —> #t
(set-equal? ‘(1 2 3) ‘((3 2)1)) —> #f
(set-equal? ‘(1 2 3) ‘((1 2 3))) —> #f
2. Two common operations on sets are union and intersection. The union of two sets is the set of all
elements that appear in either set (with no repetitions). The intersection of two sets is the set of
elements that appear in both sets.
Write Racket functions (union S1 S2)and(intersect S1 S2) that implement set union
and set intersection. For example
(union ‘(1 (2) 3) ‘(3 2 1)) —> (1 2 3 (2))
(union ‘((1 2 3)) ‘((3 4 5))) —> ((1 2 3) (3 4 5))
(union ‘((1 2 3)) ‘((3 2 1))) —> ((1 2 3))
(intersect ‘((1 2 3)) ‘((3 2 1))) —> ((1 2 3))
(intersect ‘((1 2 3)) ‘((4 5 6))) —> ()
(intersect ‘((1) (2) (3)) ‘((2) (3) (4))) —> ((2) (3))
The ordering of the elements in your answer may differ from the above.
You must use recursion, and not iteration. You may not use side-effects (e.g. set!).
The solutions will be turned in by posting a single Racket program (lab04. rkt) containing a definition of
all the functions specified.