Objectives for Section 3
After studying this section you should be able to do the following.· Recognise and use the terminology: disjoint union; power set (of a set); representation (of a data abstraction).
· Use and interpret the notation:
o X Y for the disjoint union of the sets X and Y ;
o SeqOfSetOfInt for the set consisting of all sequences whose members are sets of integers (and similar notations).
Exercises on Section 3
Exercise 7
Each of (a)–(c) is a member of one of the sets given in (i)–(iii). Say which item comes from which set.Sets: (i) SetOfSeqOfChar. (ii) SeqOfSetOfChar. (iii) SeqOfSeqOfChar.
(a) {“error1”, “error2”, “error3”}.
(b) [“error1”, “error2”, “error3”].
(c) [{‘e’,‘1’}, {‘T’}, {‘q’,‘w’,‘e’,‘r’,‘t’,‘y’}].
Answer
Solution
(a) This is a set, as shown by the outer curly brackets. Each member of this set is a string, that is, a sequence of characters. So (a) is a set of sequences of characters. It is a member of SetOfSeqOfChar.(b) This is a sequence, as shown by the outer square brackets. It is a sequence of strings. So (b) is a sequence of sequences of characters. It comes from SeqOfSeqOfChar.
(c) This is again a sequence. Each member of this sequence is a set of characters. So (c) comes from SeqOfSetOfChar.
End of answer
Exercise 8
Let Mix be the disjoint union Int Char. What is the length of the following sequence from SeqOfMix?[555, ‘5’, ‘5’, ‘5’, 11, 1].
Answer
Solution
There are six items in the sequence [555,‘5’,‘5’,‘5’,11,1] (three integers and three characters), so the length of this sequence is 6.End of answer
No comments:
Post a Comment