Question: b. (10 points) Define a recursive function reverse in Scheme which accepts only an S-list s as an argument and reverses the elements of s

 b. (10 points) Define a recursive function reverse in Scheme which

b. (10 points) Define a recursive function reverse in Scheme which accepts only an S-list s as an argument and reverses the elements of s in linear time (i.e., time directly proportional to the size of s), O(n). You may use only define, lambda, let, cond, null?, cons, car, and cdr in reverse. You may not use append or letrec in your solution. Examples: Welcome to DrRacket, version 7.5 [3m) Language: racket, with debugging, memory limit: 128 MB CPS 352 - Assignment 2 by Your Name > (reverse (1 2 3 4 5)) (5 4 3 2 1) > (reverse (1)) (1) > (reverse (21) ) (1 2) > (reverse (night and day)) (day and night) > (reverse (1 02 (3)) (45)) ) ((4 5) (2 (3)) 1) c. (10 points) Define a recursive function flatten in Scheme which accepts only an s-list (i.e., a list, possibly nested to an arbitrary depth) as an argument and returns it flattened as a list of atoms. Examples: Welcome to DrRacket, version 7.5 (3m). Language: racket, with debugging, memory limit: 128 MB. CPS 352 - Assignment 2 by Your Name > (flatten'()) O > (flatten (O)) () > (flatten '((())) () > (flatten' (a b c d)) (a b c d) > (flatten' (a (b) 0 ( 0) 0 d ((e)))) (a b c d e) > (flatten (((a b)) (c) () d ((le) () (()))))) (a b c d e f) > (flatten (a (b c) (((d)) (e)) (f g(h)))) '(a b c d e f g h) b. (10 points) Define a recursive function reverse in Scheme which accepts only an S-list s as an argument and reverses the elements of s in linear time (i.e., time directly proportional to the size of s), O(n). You may use only define, lambda, let, cond, null?, cons, car, and cdr in reverse. You may not use append or letrec in your solution. Examples: Welcome to DrRacket, version 7.5 [3m) Language: racket, with debugging, memory limit: 128 MB CPS 352 - Assignment 2 by Your Name > (reverse (1 2 3 4 5)) (5 4 3 2 1) > (reverse (1)) (1) > (reverse (21) ) (1 2) > (reverse (night and day)) (day and night) > (reverse (1 02 (3)) (45)) ) ((4 5) (2 (3)) 1) c. (10 points) Define a recursive function flatten in Scheme which accepts only an s-list (i.e., a list, possibly nested to an arbitrary depth) as an argument and returns it flattened as a list of atoms. Examples: Welcome to DrRacket, version 7.5 (3m). Language: racket, with debugging, memory limit: 128 MB. CPS 352 - Assignment 2 by Your Name > (flatten'()) O > (flatten (O)) () > (flatten '((())) () > (flatten' (a b c d)) (a b c d) > (flatten' (a (b) 0 ( 0) 0 d ((e)))) (a b c d e) > (flatten (((a b)) (c) () d ((le) () (()))))) (a b c d e f) > (flatten (a (b c) (((d)) (e)) (f g(h)))) '(a b c d e f g h)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!