Review Notes For Discrete Mathematics
Review Notes For Discrete Mathematics
Review Notes For Discrete Mathematics
Definition of divisibility: if a | b, then there exists and integer c such that b = ac.
For example, 4 | 16 and 6 | 42.
The division algorithms says that when you divide an integer a by an integer b, you will
always get a unique quotient q, and remainder r, where q and r are integers such that
The Euclidean algorithm uses repeated division to determine the greatest common divisor
of two integers a and b. At each step, the newly created remainder becomes the next
number we use to divide. Here is an example of the algorithm with a = 135 and b = 47
Problem: Determine the GCD of 135 and 47 using the Euclidean Algorithm
135 = 2x47 + 41
47 = 1x41 + 6
41 = 6x6 + 5
6 = 1x5 + 1
5 = 5x1
The greatest common divisor is the last non-zero remainder created in the process. Here,
we find gcd(135, 47) = 1.
(Note: The quotients are always the first number listed to the right of the equal sign.)
Two numbers are relatively prime if they share no common factors and their gcd is one.
The fundamental theorem of arithmetic states that all positive integers have unique prime
factorizations.
One other theorem that easily follows from the rules of divisibility:
k
dkxb + dk-1xb
k k-1
+ … + d0xb , or more succinctly,
0
d xb
i 0
i
i
.
For bases greater than 10, we start adding A, B, C, etc. to represent
further digits. For the IB exam, questions are unlikely to go past base
16 (0, 1, 2, …, 9, A, B, C, D, E, F).
The digits of the answer will simply be formed by all of the remainders,
with the first one created being the least significant.
13972 = 1724*8 + 0
1724 = 215*8 + 4
215 = 26*8 + 7
26 = 3*8 + 2
3 = 0*8 + 3
3) This will give you a base solution (x0, y0). Now, consider the
following equation:
ax + by = 0
ax = -by
a b
x y
gcd(a, b) gcd(a, b)
The "smallest" satisfying ordered pair (x,y) to this equation is
b a
( , )
gcd(a, b) gcd(a, b)
b a
x x0 k , y y0 k, k Z
gcd(a, b) gcd(a, b)
The key idea here is that adding and subtracting the given offsets from
the initial solution don't change the value of ax+by at all, thereby
creating another valid solution.
18 – 1x15 = 3
18 – 1x(123 – 6x18) = 3
18 – 1x123 + 6x18 = 3
7x18 – 1x123 = 3
7x(141 – 1x123) - 1x123 = 3
7x141 – 7x123 – 1x123 = 3
7x141 – 8x123 = 3
7x141 – 8x(405 – 2x141) = 3
7x141 – 8x405 + 16x141 = 3
23x141 – 8x405 = 3, now, multiply this through by 4:
92x141 – 32x405 = 12
So, x0 =-32 and y0 = 92 is a solution to the original equation.
Now, take
405x + 141y = 0
405x = -141y, now, just divide through by gcd(405, 141)
135x = -47y
So a solution is x=47, y=-135.
Most rules that apply to regular numbers also apply to mod. In general,
we have the following:
x a1 (mod m1 )
x a 2 (mod m2 )
x a 3 (mod m3 )
where m1, m2, and m3, are all relatively prime, and M = m1m2m3.
Well, there can be more than 3 equations, but it would be crazy for
them to give you more than that!!!
Here's how to solve the set of equations for a unique solution mod M:
M 1 x M 1 a1 (mod M )
M 2 x M 2 a 2 (mod M )
M 3 x M 3 a3 (mod M )
But, note that the following three equations will also be true:
M 1 x M 1 a1 (mod m1 )
M 2 x M 2 a 2 (mod m 2 )
M 3 x M 3 a3 (mod m3 )
2) Now, determine the values of the following: M1-1 mod m1, M2-1 mod
m2, and
M3-1 mod m3. This can be simplified by first reducing M1 mod m1, etc.
You can either solve these values by inspection or by doing the
Extended Euclidean Algorithm.
1 1
( M 1 mod m1 ) M 1 x ( M 1 mod m1 ) M 1 a1 (mod M )
1 1
( M 2 mod m2 ) M 2 x ( M 2 mod m2 ) M 2 a 2 (mod M )
1 1
( M 3 mod m3 ) M 3 x ( M 3 mod m3 ) M 3 a3 (mod M )
3
x ( ( M k1 mod mk ) M k a k )(mod M )
k 1
Problem: Find the unique solution (mod 280) to the following equations
x 3(mod 5)
x 2(mod 7)
x 5(mod 8)
56 x 168(mod 280)
40 x 80(mod 280)
35 x 175(mod 280)
Now, we must calculate 56-1 mod 5, 40-1 mod 7, 35-1 mod 8. These
reduce to 1-1 mod 5, 5-1 mod 7, 3-1 mod 8. The first of these is clearly 1.
For formalities sake, we'll go through the proper method of finding the
other two:
To find 5-1 mod 7, we want to find x such that 5x 1 mod 7. Run the
Extended Euclidean Algorithm on 7 and 5:
7 = 1x5 + 2
5 = 2x2 + 1, so
5 – 2x2 = 1
5 – 2x(7 – 1x5) = 1
5 – 2x7 + 2x5 = 1
3x5 – 2x7 = 1, considering the equation mod 7, we get
3x5 1 (mod 7), so the desired inverse is 3.
We also find that 3-1 mod 8 = 3.
Now, multiply through by these values:
56 x 168(mod 280)
120 x 240(mod 280)
105 x 525(mod 280) ,
11.6 Graphs
Our handout has all of the definitions. Here are some of the more
important ones:
Problem: See the problems in the IB questions '96 – '98 I gave you.
Here's Prim's:
1) Pick a start vertex, and let S be the set with just that vertex. Let M
be empty.
2) While (M isn't a spanning tree yet)
Here's Kruskal's
Dijkstra's algorithm solves the Single Source Shortest Path problem for
any graph with only positive edge weights.
Initialize a set S = . This set will keep track of all vertices that we have already
computed the shortest distance to from the source.
Initialize an array D of estimates of shortest distances. D[1] = 0, while D[i] = , for all
other i. (This says that our estimate from v1 to v1 is 0, and all of our other estimates from
v1 are infinity.)
A B C D E F G H I J
A 0 7 ∞ ∞ ∞ ∞ ∞ ∞ 5 3
B ∞ 0 4 7 10 ∞ ∞ ∞ ∞ ∞
C ∞ ∞ 0 2 ∞ ∞ ∞ ∞ ∞ ∞
D ∞ ∞ ∞ 0 6 8 ∞ ∞ ∞ ∞
E ∞ ∞ ∞ ∞ 0 1 ∞ ∞ ∞ ∞
F ∞ ∞ ∞ ∞ ∞ 0 ∞ ∞ ∞ ∞
G ∞ ∞ ∞ 2 3 10 0 ∞ ∞ ∞
H ∞ ∞ ∞ ∞ ∞ ∞ 1 0 ∞ ∞
I ∞ ∞ ∞ ∞ ∞ ∞ 6 4 0 ∞
J ∞ ∞ ∞ ∞ ∞ ∞ ∞ 6 1 0
Add to Set B C D E F G H I J
A 7 ∞ ∞ ∞ ∞ ∞ ∞ 5 3
J 7 ∞ ∞ ∞ ∞ ∞ 9 4 3
I 7 ∞ ∞ ∞ ∞ 10 8 4 3
B 7 11 14 17 ∞ 10 8 4 3
H 7 11 14 17 ∞ 9 8 4 3
G 7 11 11 12 19 9 8 4 3
C 7 11 11 12 19 9 8 4 3
D 7 11 11 12 19 9 8 4 3
E 7 11 11 12 13 9 8 4 3
11.10: Traveling Salesman and the "Chinese postman" problem
Given a weighted graph, the traveling salesman problem is to determine the Hamiltonian
cycle of minimum weight in the graph. (The weight of a cycle is the sums of the weights
of the edges that comprise it.)
Given a graph that satisfies the triangle inequality (namely the edge weight connecting A
to B is ALWAYS less than the sum of the edges connecting A to C and C to B), then we
can find an approximate solution to the Traveling Salesman Problems as follows:
1) Find the Minimum Spanning Tree of the graph.
2) Trace the outline of the MST, thus traversing each edge twice while visiting every
vertex.
3) Streamline that path by skipping any vertices you've already visited. The triangle
inequality guarantees that this streamlining will only reduce the cost of the cycle created
– thus guaranteeing that the final answer will be within a factor of two of the optimal.
The low bound for the weight of a Traveling Salesman Path is the weight of the
Minimum Spanning Tree of a graph.
The "Chinese Postman" problem is as follows: Given a weighted, undirected graph,
determine a walk that starts and ends at the same vertex that traverses every edge in the
graph at least once. If the graph has all even degreed vertices, then just compute the
Eulerian circuit. Otherwise, do the following:
1) List all vertices of odd degree.
2) Try listing all possible pairs of vertices.
3) For each pair, calculate the cost of moving from one vertex to the other.
4) For each possible set of pairs, calculate the extra cost incurred by "redoing" these
edges.
5) Pick the minimum possible.
For an explanation and example, go to http://people.bath.ac.uk/ma3mb/route.htm and
http://people.bath.ac.uk/ma3mb/example.htm, respectively.