Discrete Mathematics Sequence and String Sequences and strings

  • Slides: 9
Download presentation
Discrete Mathematics Sequence and String

Discrete Mathematics Sequence and String

Sequences and strings A sequence is an ordered list of numbers, usually defined according

Sequences and strings A sequence is an ordered list of numbers, usually defined according to a formula: sn = a function of n = 1, 2, 3, . . . p If s is a sequence {sn| n = 1, 2, 3, …}, p n n n p s 1 denotes the first element, s 2 the second element, … sn the nth element… {n} is called the indexing set of the sequence. Usually the indexing set is N (natural numbers) or an infinite subset of N.

Examples of sequences Examples: 1. Let s = {sn} be the sequence defined by

Examples of sequences Examples: 1. Let s = {sn} be the sequence defined by sn = 1/n , for n = 1, 2, 3, … The first few elements of the sequence are: 1, ½, 1/3, ¼, 1/5, 1/6, … 2. Let s = {sn} be the sequence defined by sn = n 2 + 1, for n = 1, 2, 3, … The first few elements of s are: 2, 5, 10, 17, 26, 37, 50, …

Increasing and decreasing A sequence s = {sn} is said to be n n

Increasing and decreasing A sequence s = {sn} is said to be n n increasing if sn < sn+1 decreasing is sn > sn+1, for every n = 1, 2, 3, … Examples: n Sn = 4 – 2 n, n = 1, 2, 3, … is decreasing: 2, 0, -2, -4, -6, … n Sn = 2 n -1, n = 1, 2, 3, … is increasing: 1, 3, 5, 7, 9, …

Subsequences A subsequence of a sequence s = {sn} is a sequence t =

Subsequences A subsequence of a sequence s = {sn} is a sequence t = {tn} that consists of certain elements of s retained in the original order they had in s n Example: let s = {sn = n | n = 1, 2, 3, …} p n 1, 2, 3, 4, 5, 6, 7, 8, … Let t = {tn = 2 n | n = 1, 2, 3, …} 2, 4, 6, 8, 10, 12, 14, 16, … p t is a subsequence of s p

Sigma notation If {an} is a sequence, then the sum m ak = a

Sigma notation If {an} is a sequence, then the sum m ak = a 1 + a 2 + … + a m k =1 This is called the “sigma notation”, where the Greek letter indicates a sum of terms from the sequence

Pi notation If {an} is a sequence, then the product m ak = a

Pi notation If {an} is a sequence, then the product m ak = a 1 a 2…am k=1 This is called the “pi notation”, where the Greek letter indicates a product of terms of the sequence

Strings p Let X be a nonempty set. A string over X is a

Strings p Let X be a nonempty set. A string over X is a finite sequence of elements from X. n n p Example: if X = {a, b, c} Then = bbaccc is a string over X Notation: bbaccc = b 2 ac 3 The length of a string is the number of elements of and is denoted by | |. If = b 2 ac 3 then | | = 6. The null string is the string with no elements and is denoted by the Greek letter (lambda). It has length zero.

More on strings Let X* = {all strings over X including } p Let

More on strings Let X* = {all strings over X including } p Let X+ = X* - { }, the set of all non-null strings p Concatenation of two strings and is the operation on strings consisting of writing followed by to produce a new string p n Example: = bbaccc and = caaba, then = bbaccccaaba = b 2 ac 4 a 2 ba Clearly, | | = | | + | |