Data and processes in computing

This free course is available to start right now. Review the full course description and key learning outcomes and create an account and enrol if you want a free statement of participation.

Free course

# 3.2 Combining data structures

In Section 2, we introduced the notation SeqOfX for the set of all sequences whose members come from the set X. In Section 2, we looked only at sequences whose members were of one of the primitive forms of data (integers, characters or Booleans). We can have sequences whose members are themselves data with a more complicated form. For example, suppose that Jo is working at the till T1 and is replaced by Jessica. We might represent this handover by the 3-tuple (Jo, T1, Jessica). Now suppose that we want to give all the handovers that occur during a particular day, in the order in which they occur. We could give this information in a sequence. This sequence would come from the set SeqOfX , where X is the Cartesian product Staff × Tills × Staff.

As another example, one might think of a sentence as a sequence of words, where each word is seen as a sequence of characters. If we did this, then the sentence would be regarded as coming from the set SeqOfSeqOfChar. We can use notations introduced earlier to show when we want to see a sentence in this way, and when it is to be regarded as a single string (from SeqOfChar).

## Activity 11

Which of the following is a member of the set SeqOfSeqOfChar?

• (a) [‘W’,‘o’,‘r’,‘d’].

• (b) “This is a sentence.”.

• (c) [“This”,“is”,“a”,“sentence”].

### Discussion

Only (c) is a member of SeqOfSeqOfChar.

• (a) This is a sequence of characters and so a member of SeqOfChar.

• (b) This is a string, so is again a sequence of characters (written in our more compact notation).

• (c) This is a sequence each of whose members is a string. Thus each item in the sequence in (c) comes from SeqOfChar. The sequence itself comes from SeqOfSeqOfChar.

Consider a computer system which has a finite set of error messages, each of which may be displayed to a cashier at the till. Suppose these messages are: “Barcode error”; “Item code not recognised” and “System error 1234”. This set of error messages can be represented thus:

Errors = {“Barcode error”, “Item code not recognised”, “System error 1234”}.

Each of these messages is given as a string, that is, as a sequence of characters. So Errors is a set of sequences of characters.

M263_1

### Take your learning further

Making the decision to study can be a big step, which is why you'll want a trusted University. The Open University has 50 years’ experience delivering flexible learning and 170,000 students are studying with us right now. Take a look at all Open University courses.

If you are new to university level study, find out more about the types of qualifications we offer, including our entry level Access courses and Certificates.

Not ready for University study then browse over 900 free courses on OpenLearn and sign up to our newsletter to hear about new free courses as they are released.

Every year, thousands of students decide to study with The Open University. With over 120 qualifications, we’ve got the right course for you.

Request an Open University prospectus