Download If a and b are integers, b 0 then a mod b is

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
GCD and related concepts
If a and b are integers, a  0 then a divides b iff
Notation: a | b
The greatest common divisor of two integers a and b
Example: gcd(18, 24)
If gcd(a, b) = 1, then a and b are relatively prime.
The least common mulltiple of integers a and b is
Example: lcm(18, 24)
Using prime factorization to find the gcd and the lcm:
Division Algorithm and the mod function
Theorem: Let a be an integer and d a positive integer. Then
there exist integers q and r such that a = dq + r, 0  r < d.
If a and b are integers, b  0 then a mod b is
Congruence mod m
If a and b are integers and m is a positive integer > 1 then a is
congruent to b modulo m iff
Notation: a  b (mod m)
The Euclidean Algorithm
Finding the greatest common divisor of a and b
Notation: gcd(a, b)
find gcd (662, 414)
find gcd(330, 156)
662 =
330 =
function gcd(a, b: positive integers)
xa
yb
while y  0
r  x mod y
xy
yr
return(x)
//Note: this differs from the text
Section 2.4 Recursion and Recurrence Relations
Two parts of a recursive definition:
1.
2.
recursively defined sequences
Each of the examples below is a recurrence relation.
Example 1: S(0) = 3 and S(n) = 2S(n – 1) + 3 for n > 0
Example 2: S(0) = 1, S(n) = 3S(n – 1) for n > 1.
Example 3: S(0) = 1, S(n) = nS(n – 1) for n > 0.
Example 4: (Example 30 p. 121) The Fibonacci sequence
The rabbit problem
A pair of young rabbits is placed on an island. A pair of rabbits
does not breed until they are 2 months old. After that, each pair
of rabbits produces another pair each month. Find the number of
rabbits after n months.
Month
breeding
pairs
young
pairs
1
2
3
4
5
Closed form
Example 6: Square Numbers
total pairs
Example 7: Triangular numbers
Recursively Defined Sets
Recursive definition of the set of powers of 3
1.
2.
Recursive definition of S = { …, -10, -5, 0, 5, 10, … }
An alphabet 
A string is
String Terminology
A bit string is
Recursive definition of the set of bit strings B
1.
2.
*--
1.
2.
3.
Concatenation
Examples and properties:
More String Examples
A palindrome is a string
1.
2.
3.
Recurrence relation for S(n) where S(n) is the number of bit
strings of length n that do not contain 11 as a substring.
Related documents