### [solution] » (a) The source code in R5RS, (b) 1-2 page description of your algorithm and its complexity

Description

The Question

(a) The source code in R5RS,

(b) 1-2 page description of your algorithm and its complexity as an ASCI text document, MS Word document, or a PDF file. Since the program you have to write is short, the description of the algorithm and the complexity analysis carry significant weight in your grade.

Write a function smallest in Scheme that takes a list L of positive and negative integers (duplicate are possible) and some auxiliary parameters of your choice. The function smallest returns the smallest, in absolute value, subset sum. Zero is not included in the list. The list L is flat, i.e., it does not contain sublists.

It is up to you to choose the auxiliary parameters that smallest takes. All auxiliary parameters must be numeric (not lists) and should have initial values set to zero. For example, if L is ?(1 2 3) and if you decide to use two additional auxiliary parameters, then smallest must be called as follows:

(smallest '(1 2 3) 0 0)

If there are three auxiliary parameters, then the function must be called:

(smallest '(1 2 3) 0 0 0 )and so on.

Note that the function must be called smallest. Other names will not be accepted. The list must precede the auxiliary parameters, which are initially set to zeroes.

Examples (for the sake of illustration, two auxiliary parameters are used):

(smallest '(2 -1 1) 0 0)returns 0.

(smallest '(2 -3 1)0 0) returns 0.

(smallest '(5 3 -1 -10)0 0) returns 1.

(smallest '(-2 7 15 -2 11 -20) 0 0) returns 0.

(smallest '(15 -14 21 -20)0 0) returns 1.

(smallest '(-24 4 -21 -25 5 -22 9) 0 0) returns 3.

The whole solution must be packed in one recursive function smallest which must look as follows:

(define smallest (lambda (<list L followed by numeric parameters of your choice initially set to zero>)

(cond

...

)))

In other words, you have to choose your auxiliary parameters and define a COND statement. Nested COND statements are allowed.

Inside COND, you can use ONLY the following constructs:

- null?

- cond

- if

- car

- cdr

- else

- +

- <

- =

- and

- abs

- min

- smallest

- the names of your parameters

- numeric constants

- parentheses

You cannot use a construct if it is not listed above. In other words, your code must define and use only one function, smallest, which must be defined using the constructs listed above. The use of built-in functions, except for min and abs, is not allowed.

The function min returns the minimum number in a list of numbers. For example, (min 1 2 3) returns 3. The function abs returns the absolute value of a number. For example, (abs -1) returns 1.

If your program uses a construct not on the list, then it is not a solution to this homework.

It is not allowed to bypass the homework requirements by packing several functions in one function definition using a numeric flag. In other words, for one value of the numeric flag the function does one thing and for other value of the flag the function does something else.

Here is an example of packing several function using a numeric flag as a second parameter:

(define smallest (lambda (list flag)

(cond ((= flag 0) the function implements one type of functionality) ((= flag 1) the function implements a second type of functionality)

(else the function implements a third type of functionality )

)))

Here, we have three functions (corresponding to flag values of 0, 1, and 2) packed in one COND statement. The flag is not related to the problem at hand and it used for the sole purpose of packing different functionalities in one COND statement. This is not allowed.

#### Solution details

Solution #00020343

##### [solution] » (a) The source code in R5RS, (b) 1-2 page description of your algorithm and its complexity.zip

This paper was answered on 14-Oct-2020

STATUS

QUALITY

Approved

Oct 14, 2020

EXPERT

Tutor

#### BEST TUTORS

We have top-notch tutors who can do your essay/homework for you at a reasonable cost and then you can simply use that essay as a template to build your own arguments.

You can also use these solutions:

• As a reference for in-depth understanding of the subject.
• As a source of ideas / reasoning for your own research (if properly referenced)
• For editing and paraphrasing (check your institution's definition of plagiarism and recommended paraphrase).
This we believe is a better way of understanding a problem and makes use of the efficiency of time of the student. 