To save content items to your account,
please confirm that you agree to abide by our usage policies.
If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account.
Find out more about saving content to .
To save content items to your Kindle, first ensure no-reply@cambridge.org
is added to your Approved Personal Document E-mail List under your Personal Document Settings
on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part
of your Kindle email address below.
Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations.
‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi.
‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
In Chapter 2 we considered a very simple data structure, the linked-linear list; and in Chapter 3 we moved on to binary trees. In this chapter we look at two much more general structures.
Firstly we shall consider trees in which nodes may have more than two branches, and in which the number of branches may vary from node to node. For want of a better name we shall call them n-ary trees.
Secondly we shall consider even more general structures which arise when more than one branch leads into a node. These structures are called directed graphs. Clearly they are more general than n-ary trees, which, therefore, may be regarded as a special case.
B-trees
We consider first the n-ary tree, and, in this section, its use in searching applications. Such trees are usually called B-trees, a convention we shall follow.
When we discussed binary trees in Chapter 2 we noted that searching, insertion and deletion were all O(log n), provided that the tree remained balanced. Although we did not discuss the topic of balance in much detail there, we referred the reader to a number of relevant techniques. B-trees arise in this connection too, though here we shall approach them from a different point of view.
Let us imagine first of all that we have a sequence of variable-length items in the store with an item with an infinite key placed at the end.
Recursion is the Cinderella of programming techniques where languages such as Pascal are concerned. All primers mention it, of course, but generally devote only a few pages to it. Rohl and Barrett's Programming via Pascal is one of the more generous: it contains one chapter of 12 pages on the subject!
Books appropriate to second courses in programming, such as those by Wirth (1976), Alagic & Arbib (1978), and the more modern data structures texts, have helped considerably; but currently there is no book devoted to the use of recursion in Pascal or similar languages.
And yet this used not to be the case: Barron's delightful little book Recursive Techniques in Programming was published in 1968! Sadly it is now out of print, and in any event was beginning to show its age. Recursion via Pascal is the author's attempt to fill this gap.
Of course, in functional programming, recursion has received its full due, since it is quite often the only repetitive construct, and this area is fairly well served with text-books. In Recursion via Pascal, most of the examples are procedures rather than functions, partly because that is the usual Pascal style and partly because we want to give examples which actually do something, like drawing the cover motif of this series, instead of merely having a value. Reading one of the functional texts after finishing this book would provide an alternative perspective.
We are going to finish our study of recursion in Pascal programming by seeing how to eliminate it. This may seem a curious thing to do given that for seven chapters we have strongly pressed the case for using recursion, but there are a number of reasons for doing so.
Firstly, it may be that the system we are using does not allow recursion. Such a restriction will not arise with Pascal, of course, but sometimes we are obliged to write in Fortran where such a restriction is part of the language definition. If we can translate a recursive procedure into a non-recursive one, then we can still retain the advantages of designing our programs recursively.
Secondly, where there are two or more forms of recursion in a procedure, its readability may be improved by the removal of one of the recursive aspects. We discussed this idea in Chapter 2 and used it in Chapters 5 and 6. For improved readability, the recursion to be eliminated must be of the preorder, linear type.
Thirdly, we may have tight space constraints or very tight time constraints and it may be that the replacement of a recursive procedure by an iterative one allows us to satisfy those constraints.
Finally, and most importantly, we may wish to consider the elimination of recursion purely to increase our understanding of recursive procedures.
One of the achievements of modern science has been the realization that very few things in the world are completely static. The behaviour of many systems, both organic and synthetic, is influenced greatly by environmental changes. This interaction between a system and its environment can be vastly complicated and yet it is an area that we must try to understand if we are going to be in a position to predict the behaviour of the system and its effect on its environment.
The particular type of analysis that we present here is based on techniques that are generally referred to as algebraic. In some cases we will draw on established algebraic results but in general it is a new type of algebra that has arisen from a desire to understand the behaviour of a system in an environment. This is perhaps the most refreshing aspect of the theory. Here, for a change, is a subject whose motivation can be linked to very real problems in the modern world, a subject that has a short but dramatic history and one which has played a large role in the development of the fundamentals of computer science. However its achievements have not been restricted to this case alone and we hope to illustrate this when we examine the examples at the end of this chapter.
In many of the systems environmental changes alter the behaviour of the system and these changes in behaviour then affect the environment in some way.
In recent years there has been a growing awareness that many complex processes can be regarded as behaving rather like machines. The theory of machines that has developed in the last twenty or so years has had a considerable influence, not only on the development of computer systems and their associated languages and software, but also in biology, psychology, biochemistry, etc. The so-called ‘cybernetic view’ has been of tremendous value in fundamental research in many different areas. Underlying all this work is the mathematical theory of various types of machine. It is this subject that we will be studying here, along with examples of its applications in theoretical biology, etc.
The area of mathematics that is of most use to us is that which is known as modern (or abstract) algebra. For a hundred years or more, algebra has developed enormously in many different directions. These all had origins in difficult problems in the theory of equations, number theory, geometry, etc. but in many areas the subject has taken on its own momentum, the problems arising from within the subject, and as a result there has been a general feeling that much of abstract algebra is of little practical value. The advent of the theory of machines, however, has provided us with new motivation for the development of algebra since it raises very real practical problems that can be examined using many of the abstract tools that have been developed in algebra.
The aim of this chapter is the description of a method for decomposing an arbitrary transformation semigroup into a wreath product of ‘simpler’ transformation semigroups, namely aperiodic ones and transformation groups. The origin of this theory is the theorem due to Krohn and Rhodes which gave an algorithmic procedure for such a decomposition. There are now various proofs of this result extant, some are set in the theory of transformation semigroups and others are concerned with the theory of state machines. In the light of the close connections between the two theories forged in chapter 2 we can expect a similar correspondence between the two respective decomposition theorems. The proof of the decomposition theorem for state machines has the advantage that it can be motivated the more easily, but at the expense of some elegance. Recently Eilenberg has produced a new, and much more efficient, decomposition and it is this theory that we will now study. It is set in the world of transformation semigroups.
Before we embark on the details let us pause for a moment and consider how we could approach the problem of finding a suitable decomposition. Let M = (Q, Σ,F) be a state machine and let |Q| = n. Consider the collection π of all subsets of Q of order n−1. Then π is an admissible subset system, and we may construct a well-defined quotient machine M/π.
We may as well begin at the beginning and this will involve us in a brief excursion through some of the fundamental concepts essential for any algebraic subject. It will also enable us to become acquainted with the notation used, although the experienced reader could easily skip through this chapter. We will assume that the reader has a knowledge of elementary set theory.
Relations
One of the fundamental concepts in mathematics is that of a relation. It can be introduced in a variety of ways but the most useful one for us is the following abstract approach.
Let A be a non-empty set. A relation, ℛ, on A is a subset ℛ ⊆ A × A. If (a, a′) ∈ A × A and (a, a′) ∈ ℛ we say that a is ℛ-related to a′. Sometimes a natural notation is used in mathematics to express this relationship between two elements of a set, for example if A = ℤ, the set of all integers, then there is a relation ≤ that can be defined on ℤ. We write a ≤ a′ if the number a′ − a is not negative and the set ℛ ⊆ ℤ × ℤ defining this relation consists of all ordered pairs (a, a′)∈ ℤ × ℤ such that a < a≤.
A relation ℛ on the set A is an equivalence relation if: