Due Wednesday November 14, 2012, 11:59am. Half marks for late submissions. No hand-marking.
For this assignment you will use an ordered set ADT ordered-set.rkt which is supplied to you. You will not modify ordered-set.rkt, but you will modify total-order.rkt, which is required by ordered-set.rkt and defines the total order for the ADT. By altering total-order.rkt, you are able to store different types of elements in an ordered set, as well as define how they should be ordered. We make one restriction to your modification: If you choose to modify the to-elem struct inside total-order.rkt, you must make sure it still has a field called data.
Remember that for a total order, we need a set of items and an operation that allows us to order all the items maintaining the properties of totality, antisymmetry, and transitivity. As an example, here is a trivial (i.e. inadequate) test program that requires total-order.rkt and ordered-set.rkt.
The file ordered-set.rkt provides the following functions:
;; In all functions below, e must be a to-elem struct ;; os-empty the empty set ;; (os-empty? s) produces true if s is empty, false otherwise ;; (os-singleton e) produces a set with one element e. ;; (os-member? s e) produces true if e is a member of s; false otherwise ;; (os-union s t) produces union of s and t in time ;; O(min(|s|,|t|) log max(|s|,|t|)) ;; (os-intersection s t) produces intersection of s and t in time ;; O(min(|s|,|t|) log max(|s|,|t|)) ;; (os-difference s t) produces difference s \ t in time ;; O(min(|s|,|t|) log max(|s|,|t|)) ;; (os-min s) produces the to-min element of s, ;; or to-min-ident if s is empty ;; running time: O(log |s|) ;; (os-max s) produces the to-max element of s, ;; or to-max-ident if s is empty ;; running time: O(log |s|) ;; (os-after s e) produces the to-min element of s which is to> than e, ;; or to-min-ident if there is no such element ;; running time: O(log |s|) ;; (os-before s e) produces the to-max element of s which is to< than e ;; or to-max-ident if there is no such element ;; running time: O(log |s|) ;; (os-op s) produces the result of applying the binary operator ;; to-op to all e in s. If s is empty, returns the to-op-ident ;; similar idea to foldl ;; running time: O(1)
You will also need to write a main program that will read from input. Recall that in Racket, we use tail recursion to do repetition (instead of iteration) and will need to use (read). Here is some sample code to get you started. To submit multiple files to Marmoset, you must combine them using zip. For example, to submit total-order.rkt and also main.rkt, execute the following command:
zip submit.zip main.rkt total-order.rktthen submit submit.zip to Marmoset.
1 3 2 1
1 2 3 3 2 1
1 3 2 1
2 1 3 3 1 2
2 4 6
4 2 6 6 2 4
1 3 2 1
1 2 2 1 3 1
score Fred 10 score Wilma 20 score Fred 20 highscore score Betty 30 highscore best Fred score Fred 25 best Fred best Barney
highscore 20 highscore 30 best Fred 20 best Fred 25 best Barney ?All commands should have running time O(log n) where n is the number of input lines. You must use ordered-set.rkt to solve this problem; you may not use lists, vectors, or any other data structure to store the players' names or scores. Hint: you can solve this problem by defining a suitable total order on a compound value consisting of the player's name and score.
score Fred 10 score Wilma 20 score Fred 20 highscore score Betty 30 highscore best Fred score Fred 25 best Fred disqualify Betty highscore best Betty
highscore 20 highscore 30 best Fred 20 best Fred 25 highscore 25 best Betty ?All commands should have running time O(log n) where n is the number of input lines. You must use ordered-set.rkt to solve this problem; you may not use lists, vectors, or any other data structure to store the players' names or scores.
score Fred 10 score Wilma 20 score Fred 20 leaders
leaders Fred WilmaThe running time of leaders must be O(m log n) where m is the number of leaders and n is the number of input lines. You must use ordered-set.rkt to solve this problem; you may not use lists, vectors, or any other data structure to store the players' names or scores.