• No results found

Sequences,Strings.pptx

N/A
N/A
Protected

Academic year: 2020

Share "Sequences,Strings.pptx"

Copied!
20
0
0

Loading.... (view fulltext now)

Full text

(1)

Sequences and Strings

(2)

Sequences

 A sequence is a special case of function, where domain of the function is a subset of

N={1,2,3,4 …}. Let s or {sn} be a sequence of values s1 , s2 , s3 , s4 ,….we use the notation sn to denote value s(n).

 Sequence of all positive even integers:

s1 =2, s2=4 s3 =6 … sn =2n …

 Depending on domain sequence can be finite or

(3)

Example

Consider the sequence bn = (1)n.

{bn} = 1, 1, 1, 1, …

{bn} denotes an infinite sequence of 1’s and

(4)

Recognizing Sequences

Sometimes, you’re given the first few terms

of a sequence, and you are asked to find the sequence’s generating function, or a

(5)

Recognizing Sequences

Examples: What’s the next number?

1,2,3,4,…1,3,5,7,9,…2,3,5,7,11,...

5 (the 5th smallest number >0)

11 (the 6th smallest odd number >0)

(6)

Sequence Notation

Given a sequence {an} defined by rule

an= n2 – 1, for all n1

values of the function are :

a1=0, a2= 3, a3= 8, a4=15

another notation of this sequence is {n2 – 1} n1

We call this representation explicit . Each value an can be computed directly for arbitrary value n1.

(7)

Sequence Notation

We can obtain member an of this sequence in a different form

a1=0, an+1= an +2n + 1, for all n1

values of the sequence are the same as before :

a1=0, a2= 3, a3= 8, a4=15

We call this representation recurrent. Each value an can be computed from the previous value an-1 .

(8)

Sequence Notation

A recurrence relation for the sequence {an} is an

equation that expresses an in terms of one or more of the previous terms of the sequence, namely,

a0, a1, . . . , an−1, for all integers n with n ≥ n0, where

n0 is a nonnegative integer. A sequence is called a

solution of a recurrence relation if its terms satisfy the recurrence relation

(9)

Example

Let {an} be a sequence that satisfies the

recurrence relation an = an−1 + an−2 for n =2, 3, 4, . . . , and suppose that a0 = 0 and a1 = 1. What are a2 , a3, a4 , a5,?

We see from the recurrence relation that

a2 = a1+a0 = 1+0 = 1, a3 = a2 +a1 = 1+1 = 2,

a4 = a3+a2 = 2+1 = 3, a5 = a4 +a3 = 3+2 = 5.

(10)

Sequence Notation

Given a sequence {am} defined on set MN a sequence {ak} defined on set KM is a

subsequence of {am}.

Sequence of all positive even numbers is a

subsequence of all positive numbers.

sequence 3,5,7,8 is a subsequence of

2,3,3,4,5,6,7,8,9 , but it is not a subsequence of

(11)

Summation Notation

Given a sequence {an}, the summation of {an}

from j to k is written and defined as follows:

Here, i is called the index of summation. Let {an}= 1,2,3,4

k j j k j i

i a a a

a    

: 1 ...

10 4 3 2 1 : 4     

(12)

Generalized Summations

 For an infinite series, we may write:

 To sum a function over all members of a set

X={x1, x2, …}:

 Or, if X={x|P(x)}, we may just write:

... ) ( ) ( : )

(  12

x f x f x f X x ... ) ( ) ( : ) (   

f x f x f x

... :  1

j j j

i

i a a

(13)

Simple Summation Example

4

2 2 2 2

2

( 1) (2 1) (3 1) (4 1) (4 1) (9 1) (16 1) 5 10 17

32

i

i

               

(14)

More Summation Examples

An infinite series with a finite sum:

Using a predicate to define a set of elements to

sum over: 87 49 25 9 4 7 5 3

22 2 2 2

10 prime)

is (

2

 x x x 2 ... 1 ... 2 2

2 41

2 1 1 0 0            

i i

(15)

Finding the sum of 1,2,…n

Consider the sum (assume n is even):

1+2+…+(n/2)+((n/2)+1)+…+(n-1)+n

n/2 pairs of elements, each pair summing to

n+1, for a total of (n/2)(n+1)=n(n+1)/2.

n+1

n+1

(16)

Example: Geometric Series

A geometric series is a series of the form

a, ar, ar2, ar3, …, ark, where a,rR.

The sum of such a series is given by:

We can reduce this to closed form via clever

manipulation of summations...

0 0

k k

i i

i i

S ar a r

 

(17)

Geometric Series closed formula

(1+r+r2+r3+…rk)(1-r)= (1-r+r-r2+r2+…-rk+1)=

=(1-rk+1)

(1+r+r2+r3+…rk)=(1-rk+1)/(1-r)=

=a(1-rk+1)/(1-r)

0 0

k k

i i

i i

S ar a r

 

(18)

Example: Infinite Geometric Series

Let x be a real number with |x| < 1. Find summation From the previous slide we take a=1 and r=x,

we have

Then we have Special case: = 2

(19)

Strings

A string over X, where X is a finite set , is a

finite sequence of elements from X.

Example : Let X={a,b,c} then sequence =

b,a,a,c,c,c is a string. We use notation as

=baaccc or shortly =ba2c3.

The length of a string is the number of its

(20)

Strings

A concatenation of strings =ac2 and =ba2c3

is string = ac2ba2c3 ,||=||+||

A substring is a subsequence of a string where

elements are consecutive.  =acc is a

substring of , but  =bcc is not a substring of

References

Related documents

This study examines presentations of women in the media through Foucauldian critical discourse analysis in order to explore dominant ideas of gender and femininity embedded

150 pages (A4 size) RISO ME9350 Standard printer Colour 1 master Colour 1 Drying Colour 2 Colour 1 printing Print drum 1 master Print drum 2 master Colour 2 master Colour 2

Keywords: fractional differential system; integral boundary conditions; singular problem; iterative positive solution; mixed monotone operator..

Bozorgmanesh M, Hadaegh F, Sheikholeslami F, Azizi F: Cardiovascular risk and all cause mortality attributable to diabetes: Tehran Lipid and Glucose Study.. Saito I, Kokubo Y,

In this prospective study we compared the rate of surgical site infection (SSI) in patients who received prophylactic antibiotics as a routine; with the rate of SSI in patients

According to this, we retain for analyse here several elements emphasised below: definition of human resource development and its related indicators; how a

This study conducts life prediction and durability assessment for the brake unit bracket of a bogie frame using a damage cumulative approach and an advanced damage tolerance

Table 8 displays the comparison of the execution time of the Cosine Similarity method which has been combined with stopword removal based Tala dictionary with the Cosine