Discrete Mathemetics - jjin-choi/study_note GitHub Wiki

Β§ Advanced Counting Techniques

1. Applications of recurrence relations (μž¬κ·€μ‹, 점화식)

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)
    • Combining case 1 and case 2
      ∴ T(j) = max(w_j + T(p(j)), T(j-1))
  • algorithm

    • the algorithm is efficient by storing the value of each T(j) after we compute it.
    • memorization

2. Solving Linear Recurrence Relations

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.

3. Divide-and-Conquer Algorithms and Recurrence Relations

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)

divide-and-conquer
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)

4. Generating Functions

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

⚠️ **GitHub.com Fallback** ⚠️