Unified Pseudo Code

This documentation is by no means comprehensive, however it should be useful when reading the soon to be published pseudo versions of the algorithms that are used in the various data structures and standalone algorithms in this project.

I will use Euclid's algorithm to demonstrate the pseudo code model.

A very english approach

Many both past and present have used the english grammar to describe the pseudo implementation of an algorithm.

Gcd (m, n)
    if n is equal to 0 then
        return m
    end if
    return Gcd(n, m mod n)
end Gcd


This approach is fine, however with more complex large algorithms the approach can become cumbersome and tedious to follow quickly.

A more streamlined approach

algorithm Gcd(m, n) 
    if n = 0 then
        return m
    end if
    return Gcd(n, m % n)
end Gcd


As you can see this approach strips the english out that can be sufficiently replaced with math operators - I'm not going to show all math operators which can be used, but I would note that in pseudo implementations some operators are specific to their scenario, e.g. Ø in the context of sets means the empty set or null set, but in general algorithms Ø is used instead of null. Also <-> does not stand for bi-implication, rather swap.

The pseudo code once posted will allow you to become familiar very quickly with the various usages.

A unified pseudo approach

This is my take on pseudo code, I introduce type annotations to reduce the complexity of identifiers.

algorithm Gcd(m:Integer, n:Integer) 
    if n = 0 then
        return m
    end if
    return Gcd(n, m % n)
end Gcd

representing complex types

There will be times when we are not dealing with primitive value types, e.g. an array or type car can be depicted by:

a:Array<Car>

Last edited Oct 14, 2007 at 4:51 PM by gbarnett, version 4

Comments

No comments yet.