Topic 4 Sequenceand Strings
Topic 4 Sequenceand Strings
4 and Strings
LEARNING OUTCOMES
By the end of this topic, you should be able to:
1. Describe the concept of sequence and operations on sequences;
and
2. Describe the concept of strings and operations on strings.
X INTRODUCTION
Sequences are used to represent ordered list of elements. A list of the letters as
they appear in a word (or normally called a string) is an example of sequence,
since the word „form‰ and „from‰ are two different words although both of them
consists of the same letters. The concept of sequence and strings will be the
subject of this topic.
4.1 SEQUENCE
SELF-CHECK 4.1
If s is a sequence, we denote the first element as s1, the second element as s2,
and so on. In general, sn denotes the nth element.
The ordered list 2, 4, 6, . 2n.. is a sequence. The first element is 2, the second
element is 4 and so on. The nth element is 2n. If we let s denote this sequence, we
have
S1 = 2 S2 = 4 S3 = 6 Sn = 2n
Example 4.1b
KLIA Shuttle Inc. charges RM 1 for the first km and 50 cents for each additional
km. In general, the cost Cn of traveling n km is 1.00 (the cost of traveling the first
km) plus 0.50 times the number (n 1) of additional km. That is,
Cn = 1 + 0.5 (n 1)
For example:
C1 = 1 + 0.5 (1 1)
= 1 + 0.5 (0)
=1
C5 = 1 + 0.5 (5 1)
= 1 + 0.5 (0)
=3
Example 4.1c
The ordered list a, a, b, a, b. is a sequence. The first element of the sequence is a,
the second element of the sequence is a and so on. If we denote this sequence, we
have
h1 = a h2 = a h3 = b hn = a h5 = b
An alternative notation for the sequence s is ¢sn². Here, s or ¢sn² denotes the
entire sequence s1, s2, s3, We use the notation sn to denote the single, nth
element of the sequence s.
Define a sequence ¢tn² by the rule tn = n2 Qtthe first five terms of this
sequence are
0 3 8 15 24
Example 4.1e
Define a sequence u by the rule un is the nth letter in the word digital. Then u1 =
d, u2 = u4 = i and u7 = l. This sequence is a finite sequence.
Word d i g i t a l
Sequence U1 U2 U3 U4 U5 U6 U7
Example 4.1f
xn = n , 1 dn d 4
Types of sequence
Example 4.1g
The sequence 2,4,6, is increasing since sn = 2n d 2(n+1) = sn+1 for all n.
Example 4.1h
The sequence s
3, 5, 5, 7, 8, 8, 13.
Is increasing since sn d sn+1 for all n.
Example 4.1i
4.1.3 Subsequence
One way to form a new sequence from a given sequence is to retain only certain
terms of the original sequence, maintaining the order terms in the given
sequence. The resulting sequence is called a subsequence of the original sequence.
Definition 4.1d: Let ¢sn² be a sequence defined for n = m, m + 1, and let n1,
n2, be an increasing sequence satisfying nk nk+1, for all k, whose values
are in the set { m, m + 1, }. We all the sequence ¢snk² a subsequence of ¢sn² .
Example 4.1j
The sequence
b, c
is a subsequence of the sequence
aabcq
Notice that the sequence
c, b
is not a subsequence of the sequence.
Table 4.2 illustrates the example:
Table 4.2: Example 4.1j
Sequence b,c
Example 4.1k
The sequence
2, 4, 8, 16
is a subsequence of the sequence
2, 4, 6, 8, 10, 12, 14, 16.
56 X TOPIC 4 SEQUENCE AND STRINGS
ACTIVITY 4.1
1. The sequence S is defined by
c, d, d, c, d, c
(a) Find s1
(b) Find s4
i=m
¦ ai a m a m+1 + ... + a n , a
i=m
i a m x a m+1 x ... x a n
Example 4.2a
Let a be sequence defined by an = 2n, nt1. Then
3 3
¦
i =1
a i = a1 a 2 + a 3 = 2 + 4 + 6 = 12 a
i=1
i = a1 x a 2 x a 3 = 2 x 4 x 6 = 48
Example 4.2b
¦ ar
i =0
i
Example 4.2c
Let a be the sequence defined by the rule an = 2(1)n, where n >1. find a formula
for the sequence s defined by
n
Sn ¦ ar
i=0
i
We find that
Sn = 2(1)1 + 2(-1)2 + 2(-1)2 + + 2(-1)n
= 2 2 + 2 +(-1)n 2 = 2 if n is even
0 if n is odd
58 X TOPIC 4 SEQUENCE AND STRINGS
ACTIVITY 4.2
gn=n2 - 3n + 3, n > 1
4
(a) Find ¦g
i =1
i
5
(b) Find ¦g
i =3
i
6
(c) Find ¦g
k =1
k
2
(d) Find g
i =1
i
3
(e) Find g
i =1
i
10
(b) Find ¦v
i =1
i
¦v v
i =1
2 n-i
4.3 STRING
ACTIVITY 4.3
Example 4.3a
q1 = b, q2 = a, q3 = a, q4 = c
q1 q2 q3 q4
b a a c
Since a string is a sequence, order is taken into account. For example, the string
baac is different from the string acab.
The string with no elements is called the null string and is denoted as O
60 X TOPIC 4 SEQUENCE AND STRINGS
Example 4.3b
O, a, b, abab, b20a5 ba
Definition 4.3c: The length of a string Dis the number of elements inDthe
length ofDis denoted by| D |
Example 4.3c
| D| =5 and | E | = 39
If D and E are two strings, the string consisting of D followed by E, written DE,
is called the concatenation of D and E.
Example 4.3d
ACTIVITY 4.4
Suppose we have three strings as follows
D = baab, E = caaba, J = bbab
(a) Write the string DE, DD, ED, E3D2J, J2E, DEJ, E2JD
(b) Compute the value of |DE|, |ED|, |DD|, |EE|
TOPIC 4 SEQUENCE AND STRINGS W 61
This PDF document contains notes about sequence and strings. If you have
installed acrobat reader on your PC you will be able to download the
notes and you can read it at anytime offline.
URL: http://cc.ee.ntu.edu.tw/~farn/courses/DM/slide/Module-11-
Sequences-color.pdf