ABSTRACT

The examples in this chapter will demonstrate the interplay of the programming techniques that we described in Chapter 4.

5.1 Example 1: Value Counting

In this example, we want to implement a generic algorithm that counts for each value in the alphabet how often it occurs in a given string. Algorithm 1 shows the general idea of this algorithm. The implementation should at least support the following kinds of

¤ CountValues (a1 . . . am) counter [c] ← 0 for each c ∈ Σ1 for i ← 1 to m do2

counter [ai] ← counter [ai] + 13 report counter4

Algorithm 1: Algorithm for Counting String Values. The algorithm counts for each value c of the alphabet Σ the number of occurrences of c in the string a1 . . . am.