Question

Implement the following Racket functions: (You must use recursion, and not iteration. You may not use side-effects (e.g. set!). )

1. Reflexive? Input: a list of pairs, L and a list S. Interpreting Las a binary relation over the set S, Reflexive? returns #

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#lang racket
;function to check reflexive relation between a set and it's relation
(define (Reflexive? L S)
(cond
;if the two lists are empty return true
((and (empty? L) (empty? S)) #t)
;if only one list is empty return false
((and (empty? L) (not (empty? S))) #f)
((and (not (empty? L)) (empty? S)) #f)
;check the element of the list S and pair in the L
; if they are equal call the function with rest of the lists
;otherwise return false
(else (if (and (eq? (first S) (first (first L))) (eq? (first S) (second (first L)))) (Reflexive? (rest L) (rest S)) #f))
)
)
;test the function
(Reflexive? '((a a) (b b) (c c)) '(a b c))
(Reflexive? '((a a) (b b)) '(a b c))
(Reflexive? '((a a) (a s) (b b) (c c)) '(a b c))
(Reflexive? '() '())

2 EN Activities DrRacket - Thu 07:20 Untitled - DrRacket* File Edit View Language Racket Insert Tabs Help Untitled (define ..

If you have any doubts please comment and please don't dislike.

Add a comment
Know the answer?
Add Answer to:
Implement the following Racket functions: (You must use recursion, and not iteration. You may not use...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that...

    Using Racket Recursion, tail-recursion, high-order functions and functional programming. 1. Modify our filter function so that it is tail-recursive. You may use the letrec form but do not use any additional forms and functions besides those we've talked about in class. (define filter (lambda (input-list func)     (cond ((null? input-list) '())           ((func (car input-list))            (cons (car input-list) (filter (cdr input-list) func)))           (else            (filter (cdr input-list) func))))) 2. Test your filter function on '(25 -22 44 56...

  • In python... All functions must use recursion. Do not use any iteration or slicing. 1. Return...

    In python... All functions must use recursion. Do not use any iteration or slicing. 1. Return the reverse of the given string. Use the index argument to keep track of position, which starts at zero. reverse_string(chars: str, index: int) -> str 2. Return the highest number in the list of integers. Use the index argument to keep track of position, which starts at zero. find_max(ints: List[int], index: int) -> int 3. Return True if the given string is a palindrome...

  • You must write each of the following scheme functions. You must use only basic scheme functions...

    You must write each of the following scheme functions. You must use only basic scheme functions do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (first-n L1 N) that returns the first N elements of L1. If N is negative, return the empty list. If N exceeds the length of L1 return all elements of L1. (first-n...

  • 3. (24%) Write the following functions. You MUST use recursion for credit. You may use the...

    3. (24%) Write the following functions. You MUST use recursion for credit. You may use the string library functions: indexing, lengthO, +, and substr(int n) (recall that substr(n) returns a string with all but the first n characters). (a) string alternate(string s): returns a string that contains every other element of s starting at the beginning. For example, alternate( 'dog' ') ''dg'' (b) string uc(string s): returns a string that is the same as s except that every upper case...

  • You must write each of the following scheme functions. You must use only basic scheme functions...

    You must write each of the following scheme functions. You must use only basic scheme functions (those described in class), do not use third-party libraries to support any of your work. Do not use any function with side effects. This problem need to use DrRacket software. Racket Language. Write a function named (key-store L1 KEY) that accepts a list of two-tuples L1 and a value KEY. This function returns the second value of the first tuple that begins with KEY....

  • Part A Analyze the following recurrences and show their time complexity functions using (I) iteration method...

    Part A Analyze the following recurrences and show their time complexity functions using (I) iteration method and (2) Master Theorem. AI. T(n) = 2T 3 A2. T(n) = 3T 2n АЗ. Т(п) — Т(п — 2) + 3 А4. Т(п) — 2Т (п — 1) + 1 A5. T(n)= 4T +n log n A6. T(n) = 3T +n log n n2 A7. T(n) = 27 Part B Do 2.3-4 (р39) and Problem 2-1 (р39) Part C Implement MERGE-SORT() algorithm that...

  • QUESTION 10 The equality relationon any set S is: A total ordering and a function with an inverse. An equivalence relation and also function with an inverse. A function with an inverse, and an equiva...

    QUESTION 10 The equality relationon any set S is: A total ordering and a function with an inverse. An equivalence relation and also function with an inverse. A function with an inverse, and an equivalence relation with as single equivalence class equal to S An equivalence relation and also a total ordering QUESTION 11 A binary operation on a set S, takes any two elements a,b E S and produces another element c e S. Examples of binary operations include...

  • (20 pts) To understand the value of recursion in a programming language: implement the binary search...

    (20 pts) To understand the value of recursion in a programming language: implement the binary search algorithm first as a recursive function and again using a conditional loop. Your program should create an array of characters holding the letters ‘A’ – ‘Z’ and find the index in the array where the letter ‘K’ is stored. You may use any programming language that supports recursion. (5pts) Define syntax and semantics and give an example. (5pts) Why is it important for a...

  • 2 Functions a. A function f : A-B is called injective or one-to-one if whenever f(x)-f(y) for some x, y E A then x = y. That is Vz, y A f(x) = f(y) → x = y. Which of the following functions are injec...

    2 Functions a. A function f : A-B is called injective or one-to-one if whenever f(x)-f(y) for some x, y E A then x = y. That is Vz, y A f(x) = f(y) → x = y. Which of the following functions are injective? In each case explain why or why not i. f:Z-Z given by f() 3r +7 (1 mark ii. f which maps a QUT student number to the last name of the student with that student...

  • Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement...

    Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement some list functionalities on an ArrrayList of generic type using type parameters in method definition Our goal for this lab is to continue using the divide and conquer approach of splitting a list into its head and tail and keep recursing on the tail (which happens to be smaller). However, instead of trying the approach on a string (a list of characters) we would...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT