



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In my class of Applied Discrete Mathematics, I take lecture note from these slides, hope these lecture slides help other student.The key point in these slides are:Sequences, Equation Game, Strings, Summations, Finite Sequences, Empty String, Index of Summation, Lower Limit, Ordered Lists of Elements, Double Summations, Algorithms, Carl Friedrich Gauss, Algorithm Examples
Typology: Slides
1 / 6
This page cannot be seen from the preview
Don't miss anything!




February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 1
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 2
Sequences represent ordered lists of elements. A sequence is defined as a function from a subset of N to a set S. We use the notation an to denote the image of the integer n. We call an a term of the sequence. Example: subset of N : 1 2 3 4 5
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 3
We use the notation {an} to describe a sequence.
Important: Do not confuse this with the {} used in set notation.
It is convenient to describe a sequence with an equation.
For example, the sequence on the previous slide can be specified as {an}, where an = 2n.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 4
1, 3, 5, 7, 9, an = 2n - 1
-1, 1, -1, 1, -1, an = (-1)n
2, 5, 10, 17, 26, an = n^2 + 1
0.25, 0.5, 0.75, 1, 1.25 an = 0.25n
3, 9, 27, 81, 243, an = 3n
What are the equations that describe the following sequences a 1 , a 2 , a 3 , ?
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 5
Finite sequences are also called strings , denoted by a 1 a 2 a 3 an.
The length of a string S is the number of terms that it consists of.
The empty string contains no terms at all. It has length zero.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 6
It represents the sum am + am+1 + am+2 + + an.
The variable j is called the index of summation , running from its lower limit m to its upper limit n. We could as well have used any other letter to denote this index.
What does stand for?
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 7
It is 1 + 2 + 3 + 4 + 5 + 6 = 21.
We write it as.
What is the value of?
It is so much work to calculate this
What is the value of?
How can we express the sum of the first 1000 terms of the sequence {an} with an=n^2 for n = 1, 2, 3, ?
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 8
It is said that Carl Friedrich Gauss came up with the following formula:
When you have such a formula, the result of any summation can be calculated much more easily, for example:
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences
9
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 10
Table 2 in 4 th^ Edition: Section 1. 5 th^ Edition: Section 3. 6 th^ and 7th^ Edition: Section 2. contains some very useful formulas for calculating sums.
In the same Section, Exercises 15 and 17 (7th^ Edition: Exercises 31 and 33) make a nice homework.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 11
Let us look at something more interesting:
Algorithms
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 12
What is an algorithm?
An algorithm is a finite set of precise instructions for performing a computation or for solving a problem.
This is a rather vague definition. You will get to know a more precise and mathematically useful definition when you attend CS420 or CS620.
But this one is good enough for now
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 19
a c d f g h j l m o p r s u v x z
binary search for the letter ‘j’
center element
search interval
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 20
a c d f g h j l m o p r s u v x z
binary search for the letter ‘j’
center element
search interval
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 21
a c d f g h j l m o p r s u v x z
binary search for the letter ‘j’
center element
search interval
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 22
procedure binary_search(x: integer; a 1 , a 2 , , an: integers) i := 1 {i is left endpoint of search interval} j := n {j is right endpoint of search interval} while (i < j) begin m := (i + j)/2 if x > am then i := m + 1 else j := m end if x = ai then location := i else location := 0 {location is the subscript of the term that equals x, or is zero if x is not found}
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 23
Obviously, on sorted sequences, binary search is more efficient than linear search.
How can we analyze the efficiency of algorithms?
We can measure the
These measures are called computational complexity and space complexity , respectively.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 24
What is the time complexity of the linear search algorithm?
We will determine the worst-case number of comparisons as a function of the number n of terms in the sequence.
The worst case for the linear algorithm occurs when the element to be located is not included in the sequence.
In that case, every item in the sequence is compared to the element to be located.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 25
Here is the linear search algorithm again: procedure linear_search(x: integer; a 1 , a 2 , , an: integers) i := 1 while (i ≤ n and x ≠ ai) i := i + 1 if i ≤ n then location := i else location := 0 {location is the subscript of the term that equals x, or is zero if x is not found}
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 26
For n elements, the loop
while (i ≤ n and x ≠ ai) i := i + 1 is processed n times, requiring 2n comparisons. When it is entered for the (n+1)th time, only the comparison i ≤ n is executed and terminates the loop. Finally, the comparison if i ≤ n then location := i is executed, so all in all we have a worst-case time complexity of 2n + 2.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 27
procedure binary_search(x: integer; a 1 , a 2 , , an: integers) i := 1 {i is left endpoint of search interval} j := n {j is right endpoint of search interval} while (i < j) begin m := (i + j)/2 if x > am then i := m + 1 else j := m end if x = ai then location := i else location := 0 {location is the subscript of the term that equals x, or is zero if x is not found} February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 28
What is the time complexity of the binary search algorithm?
Again, we will determine the worst-case number of comparisons as a function of the number n of terms in the sequence.
Let us assume there are n = 2k^ elements in the list, which means that k = log n.
If n is not a power of 2, it can be considered part of a larger list, where 2k^ < n < 2k+1.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 29
In the first cycle of the loop
while (i < j) begin m := (i + j)/2 if x > am then i := m + 1 else j := m end
the search interval is restricted to 2k-1^ elements, using two comparisons.
February 7, 2013 Applied Discrete Mathematics Week 2: Functions and Sequences 30
In the second cycle, the search interval is restricted to 2 k-2^ elements, again using two comparisons.
This is repeated until there is only one (2^0 ) element left in the search interval.
At this point 2k comparisons have been conducted.