Question
Answer must be in racket ;************************************************************ ; ** problem 3 ** (10 points) ; Write one procedure ; (total-order? compare? domain) ; that takes a
Answer must be in racket
;************************************************************ ; ** problem 3 ** (10 points) ; Write one procedure
; (total-order? compare? domain)
; that takes a predicate (compare? x y) and a list of values domain ; such that whenever x and y are values from domain, (compare? x y) ; returns either #t or #f. ; The procedure returns #t if compare? is a total order on domain ; (that is, satisfies the four properties above for all x, y, z from domain), ; and #f otherwise.
; Hint: it might be helpful to write a procedure to check these conditions ; one pair x, y at a time.
; QUESTION: What is the running time of your procedure in terms of n, ; the number of elements in the domain. Assume compare? takes time O(1). ; Give your answer in terms of O, Theta, or Omega, as appropriate and ; explain why it is correct. Replace "replace" in total-order-runtime ; with your answer.
; Examples ;> (total-order? <= '(1 3 5 4)) ;#t ;> (total-order? < '(1 3 5 4)) ;#f ;> (total-order? >= '(3 2 4 5 1)) ;#t ;> (total-order? string<=? (list "hi" "hey" "hello")) ;#t ;> (total-order? equal? (list "hi" "hey" "hello")) ;#f ;************************************************************
(define total-order-runtime "replace") ; Explain your answer here.
(define (total-order? compare? domain) "total-order? is not defined yet")
;************************************************************
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started