Chapter 3-Sequence and Strings

Embed Size (px)

Citation preview

  • 8/12/2019 Chapter 3-Sequence and Strings

    1/19

    Chapter 3 Sequence and String

    CSNB 143Discrete Mathematical Structures

    Revised on 2011

  • 8/12/2019 Chapter 3-Sequence and Strings

    2/19

    OBJECTIVESStudents should be able to differentiate few characteristics ofsequence.

    Students should be able to use sequence and strings.Students should be able to concatenate string and know howto use them.

  • 8/12/2019 Chapter 3-Sequence and Strings

    3/19

    What, which, where, whenKnowledge about sequence

    Finite (Clear / Not Clear )Infinite (Clear / Not Clear )

    Recursive (Clear / Not Clear )Explicit (Clear / Not Clear )Increasing (Clear / Not Clear )Decreasing (Clear / Not Clear )

  • 8/12/2019 Chapter 3-Sequence and Strings

    4/19

    String (Clear / Not Clear )Concatenation (Clear / Not Clear )Subsequence (Clear / Not Clear )

  • 8/12/2019 Chapter 3-Sequence and Strings

    5/19

    SequenceA list of objects in its order. That is, taking order as animportant thing.A list in which the first one should be in front, followed bythe second element, third element and so on.List might be ended aftern , n N and it is named asFiniteSequence . We called n as an index for that sequence.List might have no ending value, and this is called asInfinite

    Sequence. Elements might be redundancy.

  • 8/12/2019 Chapter 3-Sequence and Strings

    6/19

    Ex 1: S = 2, 4, 6, , 2 n S = S1, S2, S3, Sn

    where S1=2, S2= 4, S3=6, Sn = 2 n

    Ex 2:

    T = a, a, b, a, bwhere T1=a, T 2=a, T 3=b, T 4=a, T 5=b

  • 8/12/2019 Chapter 3-Sequence and Strings

    7/19

    If the sequence is depending on the previous value, it is calledRecursive Sequence.

    If the sequence is not depending on the previous value, inwhich the value can be directly retrieved, it is calledExplicit Sequence.

  • 8/12/2019 Chapter 3-Sequence and Strings

    8/19

    Ex 3:An = An-1 + 5; A1 = 1, 2 n < , this is a recursive sequence

    where: A2 = A1 + 5A3 = A2 + 5

    Ex 4:An = n 2 + 1; 1 n < , this is an explicit sequencewhere: A1 = 1 + 1 = 2

    A2 = 4 + 1 = 5A3 = 9 + 1 = 10That is, we can get the value directly, without any dependency toprevious value.

  • 8/12/2019 Chapter 3-Sequence and Strings

    9/19

    Both recursive and explicit formula can have both finite andinfinite sequence.Ex 5: Consider all the sequences below, and identifywhich sequence isrecursive/explicit andfinite/infinite.

    a) C1 = 5, C n = 2Cn-1, 2 n 6

    b) D1 = 3, D n = Dn-1 + 4c) Sn = (-4)n, 1 n d) Tn = 92 5n , 1 n 5

  • 8/12/2019 Chapter 3-Sequence and Strings

    10/19

    Both sequences also can have anIncreasing or Decreasing sequence.A sequence is said to be increased if for each Sn, the value isless than Sn + 1 for alln ,

    Sn Sn + 1 ; all n

    A sequence is said to be decreased if for each Sn the value is

    bigger than Sn + 1 for alln, Sn Sn + 1 ; all n

  • 8/12/2019 Chapter 3-Sequence and Strings

    11/19

    Ex 6: Determine either this sequence in increasing ordecreasing.

    Sn = 2(n

    + 1),n

    1Xn = () n, n 1S = 3, 5, 5, 7, 8, 8, 13

  • 8/12/2019 Chapter 3-Sequence and Strings

    12/19

    StringSequences or letters or other symbols that is written withoutcommas are also referred as strings.

    An infinite string such as abababa may be regarded asinfinite sequence of a,b,a,b,a,b,a

    The set corresponding to sequence is simply the set of

    all distinct elements in the sequence.E.g 1: 1,4,8,9,2 is {1,4,8,9,2} E.g 2 : a,b,a,b,a,b,a is simply {a, b}

  • 8/12/2019 Chapter 3-Sequence and Strings

    13/19

    A string over A set is a finite sequence of elements from A.Let A = {a, b, c}. If we let

    A1 = b, A2 = a, A3 = a, A4 = c

    Then we obtain a string over A. The string is written baac.Since a string is a sequence, order is taken into account. Forexample the string baac is different from acab.Repetition in a string can be specified by superscript. For

    example the string bbaaac may be written b2a3c.

  • 8/12/2019 Chapter 3-Sequence and Strings

    14/19

    The string with no element is call the null string and isdenoted as . We let setA* denote the set of all strings overA, including the null string.

    Ex 10: Let sayA = {a, b, c, , z} Then

    A* = {aaaa, computer, denda, pqr, sysrq, }

    Or let X = {a, b }. Some elements of X* are:a, b, baba, , b2a29 ba

  • 8/12/2019 Chapter 3-Sequence and Strings

    15/19

    That is, all finite sequence that can be build from A, containsall words either it has any meaning or not, regardless itslength.

    The number of elements in any string A is called ElementsLength, denoted as |A|.

    Ex 11:

    If A = abcdez, then |A| = 26.

  • 8/12/2019 Chapter 3-Sequence and Strings

    16/19

    ConcatenationIf W1 and W2 are two strings, the string consisting of W1 followed by W2 written W1. W2 is called concatenation ofW1 and W2 :

    W1.W2 =A1A2A3AnB1B2B3Bm where W1.W2

    And it is known thatW1. = W 1 and .W1 = W 1

  • 8/12/2019 Chapter 3-Sequence and Strings

    17/19

    Ex 12: Let say R = aabc, S = dacbSo, R.S = aabcdacb S.R = dacbaabc R. = aabc .R = aabc

  • 8/12/2019 Chapter 3-Sequence and Strings

    18/19

    SubsequenceIt is quite different from what we have learn in subsetA new sequence can be build from original sequence, but theorder of elements must remains.

    Ex 13: T = a, a, b, c, q

    where T1=a, T 2=a, T 3=b, T 4=c, T 5=q

    S = b, c is a subsequence of T but R = c, b is not a subsequence of T

    *Take note that the order in which b and c appears must be thesame with the original sequence.

  • 8/12/2019 Chapter 3-Sequence and Strings

    19/19

    Exercise1. List all string on X = {0, 1}, with length 2.2. With your own words, explain the meaning of sequence.

    What is the basic difference between sequence and set?