Question

In: Computer Science

1. Write a Racket function (set-equal? L1 L2) that tests whether L1 and L2 are equal....

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!).

Solutions

Expert Solution


Related Solutions

In Haskell Write a function equal that returns whether two sets are equal. equal :: Set...
In Haskell Write a function equal that returns whether two sets are equal. equal :: Set -> Set -> Bool
Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩...
Given two sorted lists, L1 and L2, write an efficient C++ code to compute L1 ∩ L2 using only the basic STL list operations. What is the running time of your algorithm?
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and...
1) Equations for two lines L1 and L2 are given. Find the angle between L1 and L2. L1: ? = 7 + 2?, ? = 8 − 4?, ? = −9 + ? L2: ? = −8 − ?, ? = 3 − 3?, ? = 4 + 3? 2) Find polar form of complex number z : ?) ? = 4√3 − 4? ?) ? = 2√3 − 2i
create a function to merge and concatenate two linked list l1 =[1,2,4] and l2=[1,3,4]. dont modify...
create a function to merge and concatenate two linked list l1 =[1,2,4] and l2=[1,3,4]. dont modify l2 (the nodes inserted in l1 should be copies of l2 class Node(object): def __init__(self, data): self.data = data self.next = None    class LinkedList(object): def print_list(self): cur_node = self.head while cur_node: print(cur_node.data) cur_node = cur_node.next def __init__(self): self.head = None;    def append(self, data): new_node = Node(data) if self.head is None: self.head = new_node return last_node = self.head while last_node.next: last_node = last_node.next...
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that...
PLEASE GIVE THE CODE IN RACKET PROGRAMMING RECURSIVE LANGUAGE ONLY Write a Racket function "combine" that takes two functions, f and g, as parameters and evaluates to a new function. Both f and g will be functions that take one parameter and evaluate to some result. The returned function should be the composition of the two functions with f applied first and g applied to f's result. For example (combine add1 sub1) should evaluate to a function equivalent to (define...
Determine whether the lines and are parallel, skew, or intersecting. L1:X=1+2t, Y=2+3t , z=3+4t L2: X=-1+6s,...
Determine whether the lines and are parallel, skew, or intersecting. L1:X=1+2t, Y=2+3t , z=3+4t L2: X=-1+6s, Y=3-s ,z=-5+2s
Write a Racket function that will take a list of numbers as a parameter and return...
Write a Racket function that will take a list of numbers as a parameter and return true if they all are positive, and false otherwise. You are NOT required to check the type of elements in the list. (please do on racket language)
1. Perform a Desk check for the following pseudocode algorithm L1: Program AddFirst5Numbers; L2: Data Counter...
1. Perform a Desk check for the following pseudocode algorithm L1: Program AddFirst5Numbers; L2: Data Counter as Integer; L3: Data Sum as Integer; L4: Counter:= 1; L5: Loop until Counter = 5 L6: Sum := Sum + Counter; L7: counter := counter + 1; L8: Next Loop; L9: Output “The sum is”, Sum; L9: End AddFirst5Numbers; 2. Write a pseudocode algorithm to print the following pattern 2 4 6 8 10 3. Using nested loops, write a pseudocode algorithm to...
In Python iOverlap (a1, a2, b1, b2) Write the function iOverlap that tests whether 2 closed...
In Python iOverlap (a1, a2, b1, b2) Write the function iOverlap that tests whether 2 closed intervals overlap. It takes 4 numbers (ints or floats) a1, a2, b1, b2 that describe the two closed intervals [a1,a2] and [b1,b2] of the real number line, and returns True if these two closed intervals overlap (even if at only one point) and False otherwise. If a1>a2, then the interval [a1,a2] is empty. If b1>b2, then the interval [b1,b2] is empty. Both intervals are...
Let L1 be the line passing through the point P1=(−3, −1, 1) with direction vector →d1=[1, −2, −1]T, and let L2 be the line passing through the...
Let L1 be the line passing through the point P1=(−3, −1, 1) with direction vector →d1=[1, −2, −1]T, and let L2 be the line passing through the point P2=(8, −3, 1) with direction vector →d2=[−1, 0, 2]T. Find the shortest distance d between these two lines, and find a point Q1 on L1 and a point Q2 on L2 so that d(Q1,Q2) = d. Use the square root symbol '√' where needed to give an exact value for your answer. d =  Q1 = Q2 =
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT