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

Given two sorted lists L1 and L2, write a procedure to compute L1∪L2 using only the...
Given two sorted lists L1 and L2, write a procedure to compute L1∪L2 using only the basic list operations. Pseudo-code is acceptable.
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?
Create a F# Function. Function Signature: zip L1 L2 The function zip combines the elements of...
Create a F# Function. Function Signature: zip L1 L2 The function zip combines the elements of two lists pairwise, resulting in a list of tuples, where the first tuple in the list contains the first element of L1 as the first element, and the first element of L2 as the second element // // zip L1 L2 // // Zip two lists // // Returns list of tuples // // Examples: // zip [] [] => [] // zip [1]...
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
Write in Racket Language Write a recursive Racket function "all-same" that takes a string as a...
Write in Racket Language Write a recursive Racket function "all-same" that takes a string as a parameter and evaluates to true iff every character in the string is the same. Note: A string of length 0 or 1 should also evaluate to true.
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...
Write in Racket language. Write a non-recursive Racket function called "keep-short-norec" that takes an integer and...
Write in Racket language. Write a non-recursive Racket function called "keep-short-norec" that takes an integer and a list of strings as parameters and evaluates to a list of strings. The resulting list should be all strings on the original list, maintaining their relative order, whose string length is less than the integer parameter. For example, (keep-short-rec 3 '('abc' 'ab' 'a')) should evaluate to '('ab''a') because these are the only strings shorter than 3.
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
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT