Professional Documents
Culture Documents
International University
School of Computer Science and Engineering
Session 5&6
Number Theory
Dr.Nguyen Van Sinh
nvsinh@hcmiu.edu.vn
Outline
Ø Application of Congruence:
q Hashing function
q Cryptography
q .. See 3.7 (textbook)
Classwork!
Sequence and
Summation
Sequence
A sequence is an ordered list of elements.
Examples of Sequence
Examples of Sequence
Examples of Sequence
Ø Not all sequences are arithmetic or geometric
sequences.
Ø An example is Fibonacci sequence
Examples of Sequence
More on Fibonacci Sequence
Examples of Golden Ratio
Sequence Formula
Sequence Formula
Some useful sequences
Summation
Evaluating sequences
Arithmetic Series
Consider an arithmetic series a1, a2, a3, …, an. If the
common difference (ai+1 - a1) = d, then we can compute
the kth term ak as follows:
a2 = a1 + d
a3 = a2 + d = a1 +2 d
a4 = a3 + d = a1 + 3d
ak = a1 + (k-1).d
Evaluating sequences
Sum of arithmetic series
Solve this
1+2+3+…+n=?
[Answer: n.(n+1) / 2]
why?
Calculate 12 + 22 + 32+ 42 + … + n2
[Answer n.(n+1).(2n+1) / 6]
Can you evaluate this?
Does it help?
Double Summation
Useful summation formulae
Algorithms and
Complexity
What is an algorithm
A finite set (or sequence) of precise
instructions for performing a computation.
max := a1
Given n elements,
can you count the
i := 2 total number of
operations?
no
max < ai
yes
max = ai i: = i + 1
no
i = n?
yes
end
Time complexity of algorithms
Measures the largest number of basic operations
required to execute an algorithm.
k := 1
(1 operation)
while k ≤ n do
if then
Example of a sorting algorithm
start
i:=1
Given n
j: = i+1 elements, can
you count the
total
ai > aj
no number of
yes operations?
swap ai, aj i: = i + 1
j: = j + 1
j = n?
no
yes
i = n-1?
no
yes
end
Bubble Sort
Bubble Sort
1 2
A C B
If you need to reach point B from point A in the fewest number of hops,
Then which route will you take? If the knowledge is local, then you are
Tempted to use a greedy algorithm, and reach B in 5 hops, although
It is possible to reach B in only two hops.
Other classification of problems
l Problems that have polynomial worst-case
complexity are called tractable. Otherwise they
are called intractable.
l Problems for which no solution exists are
known as unsolvable problems (like the halting
problems). Otherwise they are called solvable.
l Many solvable problems are believed to have
the property that no polynomial time solution
exists for them, but a solution, if known, can be
checked in polynomial time. These belong to
the class NP (as opposed to the class of
tractable problems that belong to class P)
The Halting Problems
The Halting problem asks the question.