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:
?View Code SCHEME1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
;;;;;;QUICKSORT;;;;;;;;
;myquicksort: listOfNumbers->listOfNumbers
; Sorts the input by positioning the input around the first element(pivot) and recursively sorts the [...]
Here is a procedure that counts patterns in a sequence of words:
?View Code SCHEME1
2
3
4
5
6
7
8
9
(define match
(lambda (pattern text)
(helper pattern text 0 pattern)))
(define (helper p t c o-p)
(cond ((null? p) (helper o-p t (+ 1 c) o-p))
((null? t) c)
((eq? (car p) (car t)) (helper (cdr p) (cdr t) c o-p))
(else (helper [...]
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.
?View Code SCHEME1
2
3
4
5
6
7
8
9
10
(define tolerance 0.00001)
(define [...]
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:
?View Code SCHEME(define (half-interval-method f a b)
(let ((a-value (f a))
(b-value (f b)))
(cond [...]
In order to develop a derivative calculator in Scheme we need to learn about symbols. First we need to learn quote keyword.
(define x 3)
x
(quote x)
gives us
3
x
See that quote procedure returns the actual symbol used not the value of the symbol x. What quote does is to create a list of supplied expression. Input to our [...]
HOPs stands for higher order procedures. They are actual procedures which input or oupt other procedures or both. We will come ack to HOPs later. Lists in Scheme are created by the keyword list.
(list 1 2 3) creates a list ‘(1 2 3). The ‘ actually identifies this expression as list and states that it should [...]
Tower of Hanoi is a famous puzzle. If you do not know anything about it please check this site to have an idea.
http://www.mazeworks.com/hanoi/index.htm
In this puzzle the aim is to take the blocks from one stick and put them in another one in the same order. Smaller blocks cannot go over the bigger ones of course. [...]
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 Scheme)
A [...]
In this post we will examine an algorithm example. The question is: In how many different ways can we add up to 1 dollar by using 1,5 10, 25, 50 cents?
First, we need to simplify or clarify the question. The ways that we can get to an amount of money with n different changes is
-the [...]
Scheme is a dialect of Lisp language. It is useful in artificial intelligence research. Here we give some introductory information.
Scheme uses prefix notation. For example; 3 + 4 is written as (+ 3 4)
There are many built-in definitions in Scheme +,-,*,/ are some of these. However, you can also define your own procedures and variables. [...]