Discrete Mathemetics - jjin-choi/study_note GitHub Wiki
1) Modeling with recurrence relations
-
example 1. Counting rabbits
- Fibonacci sequence : f_n = f_(n-1) + f_(n+2)
-
example 2. Hanoi puzzle
-
The goal of the puzzle is to have all the disks on the second peg in order of size, with the largest on the bottom.
β΄ H_n = H_(n-1) + 1 + H_(n-1) -
where H_(n-1) denotes the number of moves needed to solve with (n-1) disks.
β΄ H_n = 2^n - 1 and H_1 = 1
-
-
example 3. Counting bits strings of length n with no two consecutive 0
- a_n denotes the number of bit strings of length n that don't have two consecutive 0.
- 2 types (those that end in 1 / those that end in 0)
- those that end in 1 β a_(n-1) with 1 added at the end
- those that end in 0 β must have 1 as their (n-1)st bit β a_(n-2) with 10 added at the end
- a_1 = 2, a_2 = 3
β΄ a_n = a_(n-1) + a_(n-2) for n β₯ 3
2) Algorithms and recurrence relations
-
dynamic programming : when it recursively breaks down a problem into simpler overlapping sub-problems, and computes the solution using the solutions of the sub-problems.
-
example
- total n talks, where talk_j begins at time s_j, ends at time e_j, and w_j students
- T(j) maximum # of total attendees for an optimal schedule from the first j talks.
- sort the taks in order of increasing end time
- renumber the talks so that e_1 β€ e_2 β€ ... β€ e_n
- compatible if the times they are scheduled do not overlap
- p(j) = i, for which e_i β€ s_j, i < j (talk_j κ° μμνκΈ° μ μ λλλ κ°μ₯ λ¦μ talk_i)
-
solution
- first, develop a key recurrence relation.
- case 1 ) talk_j belongs to the optimal schedule
- case 2 ) talk_j doesn't belongs to the optimal schedule
- case 1
- p(j)+1, ..., j-1 μ optimal scheduleμ ν¬ν¨λ μ μμ (β΅ not compatible with j)
- optimal scheduleμ 1, ..., p(j) λ‘ κ΅¬μ±λμ΄μ§λ€.
β΄ T(j) = w_j + T(p(j))
- case 2
- optimal schedule from talks 1,...,j is the same as an optimal schedule from talks 1,...,j-1.
β΄ T(j) = T(j-1)
- optimal schedule from talks 1,...,j is the same as an optimal schedule from talks 1,...,j-1.
- Combining case 1 and case 2
β΄ T(j) = max(w_j + T(p(j)), T(j-1))
- first, develop a key recurrence relation.
-
algorithm
- the algorithm is efficient by storing the value of each T(j) after we compute it.
- memorization
1) Introduction
-
Definition 1. A linear homogeneous ( f(ax) = a^nf(x) ) recurrence relation of degree k with constant coefficients is a recurrence relation of the form (previous k terms of the sequence)
a_n = c_1 * a_(n-1) + c_2 * a_(n-2) + ... c_k * a_(n-k)- a_n = a_(n-5) : linear homogeneous recurrence relation of degree 5
-
Link: homogeneous
2) Solving linear homogeneous recurrence relations (LHRR) with constant coefficients
-
First, solutions of the form a_n = r^n where r is a constant.
- r^n = c_1 * r^(n-1) + ... + c_k * r^(n-k)
- divide by r^(n-k)
- r^k - c_1 * r^(k-1) _ ... - c_(k-1) * r - c_k = 0
- μ μμ νΉμ± λ°©μ μ μ΄λΌκ³ νκ³ μ΄ λ°©μ μμ κ·Όμ νΉμ±κ·Ό (characteristic root) λΌκ³ νλ€.
-
Second, linear combination of two solutions of LHRR is also a solution.
-
Theorem 1. Let c_1 and c_2 be real numbers. Suppose that r^2 - c_1 * r - c_2 = 0 has two distinct roots r_1 and r_2. Then the sequence {a_n} is a solution of the RR. a_n = c_1 * a_(n-1) + c_2 * a_(n-2) β a_n = b_1 * (r_1)^n + b_2 * (r_2)^n where b_1 and b_2 are constants.
-
λμ°¨ μ ν μ νμ (LHRR) μ μΌλ°ν a_n μ΄ μκ³ , μ΄μ kμ°¨ νΉμ± λ°©μ μμ μλ‘ λ€λ₯Έ νΉμ±κ·Όμ΄ r_1, r_2 μ΄λ©΄, λμ°¨ μ νμ νμμ μΌλ°ν a_n μ νΉμ±κ·Όλ€μ μΌμ°¨κ²°ν©μΌλ‘ λνλΌ μ μλ€.
-
Link : Recurrence Relation
-
example 3. LHRR
- a_n = a_(n-1) + 2 * a_(n-2) with a_0 = 2, a_1 = 7
- r^2 - r - 2 = 0 and roots are 2, -1. β΄ a_n = b_1 * 2^n + b_2 * (-1)^n
-
Theorem 2. Let c_1 and c_2 be real numbers with c_2 β 0. Suppose that r^2 - c_1 * r - c_2 = 0 has only one root r_0. A sequence {a_n} is a solution of the recurrence relation a_n = c_1 * a_(n-1) + c_2 * a_(n-2) β a_n = b_1 * (r_0)^n + b_2 * n * (r_1)^n where b_1 and b_2 are constants.
1) Divide-and-Conquer RR
-
Divide-and-Conquer
- size n problem β a sub-problems * size (n/b)
- g(n) extra operations are required in the conquer step to combine the solutions of the sub-problems into a solution of the original problem.
- f(n) represents the # of operations required to solve the problems of size n β΄ f(n) = a f(n/b) + g(n)
- ex) merge sort, binary search, a^b
-
example
- size n μ 2 λΆν λ‘ λλλ€ λ³΄λ©΄ μ΄ log_2 n λ¨κ³κΉμ§ λλ μ§ (ex) 8κ°λ₯Ό 2κ°μ© λλλ©΄ 3λ²)
- β λλμ΄μ§λ λ¬Έμ μ κ°μ (a)
- β‘ λΆν ν λ¬Έμ μ ν¬κΈ° (n/b)
- β’ κ° λ¬Έμ λ§λ€ λ³ν© νΉμ μ 볡 λ¨κ³μμ 걸리λ μκ° (d)
Link: Divide-and-Conquer
- ν κ°μ λ°μ΄ν°λ₯Ό μ²λ¦¬νλλ° νμν μκ°μ΄ c μ΄λ©΄ n κ° λ°μ΄ν° μ²λ¦¬νλλ°λ cn
- bλ‘ λλ μ iλ² λΆκΈ°νλ©΄ λΆκΈ°νμ i = log_b n
-
Theorem 1.
Let f(n) = a f(n/b) + c- f(n) = O( n^(log_b a) ) if a > 1
- f(n) = O( log n ) a = 1
-
Theorem 2. Master theorem
Let f(n) = a f(n/b) + c * n^d whenever n = b^k- f(n) = O( n^d ) if a < b^d
- f(n) = O( n^d * log n ) if a = b^d
- f(n) = O( n^(log_b a) ) if a > b^d
-
example 12. the closest-pair problem
- brute-force : O(n^2) (β΅ C(n,2) = n(n-1)/2 )
- for simplicity, n = 2^k
- when n=2, only one pair of points
- divide-and-conquer cases
- (1) both left β d_L (2) both right β d_R (3) one in left one in right
- d = min(d_L, d_R)
1) Introduction
-
definition 1. Generating function (λ©±κΈμ νν)
G(x) = a_0 + a_1 * x + ... a_k * x^k + ... = sum (a_k * x^k) (0 β€ k β€ β) -
example
- nκ°μ μλ‘ λ€λ₯Έ μ’ λ₯ μ€ rκ° μ ννκΈ° (λ¨, each kind λ§λ€ μ΅μ 1κ°λ λ°λμ 골λΌμΌ ν¨)
ref : discrete mathematics and its applications