Sorting Algorithms in Scheme

I will talk about three distinct sorting algorithms. Perhaps, the easiest to implement is the quicksort. In short, it sorts the input by positioning the input around the first element(pivot) and recursively sorts thepartitions. Here is the implementation:

The second algorithm is insertion sort. It sorts the list through successive insertions tocorrect places.

[…]
Continue reading…

 

Pattern Matching in Scheme

Here is a procedure that counts patterns in a sequence of words:

If we define an example as (define *test* ‘(a b c a b a b a b c b c b c a b c)) Then we get (match ‘(a b c) *test*) => 3 (match ‘(a b c) ‘()) => 0 […]
Continue reading…

 

Finding Fixed Points in Scheme

A number x is called a fixed point of a function if x satisfies the equation f(x)=x. We can locate a fixed point by beginning with an initial guess and applying f repeatedly, f(x), f(f(x)), f(f(f(x))),… Note that we need a tolerance to find two succesive values whose difference is less than it.

Then […]
Continue reading…

 

Half-Interval Method in Scheme

Half-interval method is used to find roots of an equation given that points a and b are f(a)<0<f(b). Thus, we assume that we are initially given the funtion together with points at which its values are negative and positive. Here is the algorithm:

This following example uses half-interval method to approximate pi as the […]
Continue reading…

 

Some Scheme Tools

order to develop your own Scheme programs you need some tools. Actually, there are two considerable options which are MIT Scheme and PLT Scheme. Both have some debugging options, but it is easier to use PLT Scheme since it has a more developed GUI interface. It is up to you which one to choose. http://download.plt-scheme.org/drscheme/ (PLT […]
Continue reading…