Midterm Methods Flashcards
(19 cards)
1
Q
Propose-and-Reject Algorithm (Gale-Shapley)
A
- Each unmatched job proposes to its highest-ranked remaining candidate
- Each candidate tentatively accepts their best offer and rejects others
- Rejected jobs mark candidates as unavailable and try next preference
- Repeat until all jobs are matched
2
Q
Finding an Eulerian Tour
A
- Start at any vertex
- Follow unused edges, deleting them as you go
- If stuck at a vertex with no unused edges, place the path there
- Start a new path from a vertex with unused edges that’s already in the tour
- Merge the new path with the existing tour
- Repeat until all edges are used
3
Q
Fast Modular Exponentiation
A
- Convert exponent to binary
- Start with
result = 1
- For each bit from left to right:
a. If current bit is0
→result^2 (mod m)
b. If current bit is1
→result^2 * base (mod m)
- Return final result
4
Q
Euclid’s Algorithm for GCD
A
- If
y = 0
, returnx
- Otherwise, return
gcd(y, x mod y)
- Repeat until remainder is
0
5
Q
Extended Euclid’s Algorithm
A
- If
y = 0
, return(1, 0, x)
representing1·x + 0·y = x
- Otherwise, recursively find
(a', b', d) = extended_gcd(y, x mod y)
- Return
(b', a' - b'·⌊x/y⌋, d)
representinga·x + b·y = d
- Base values are returned up the recursion to find coefficients
6
Q
RSA Setup Procedure
A
- Choose two distinct large prime numbers
p
andq
- Compute
N = p × q
- Calculate
φ(N) = (p-1)(q-1)
- Choose public exponent
e
where1 < e < φ(N)
andgcd(e, φ(N)) = 1
- Determine private key
d
whered·e ≡ 1 (mod φ(N))
- Public key is
(N, e)
, private key isd
7
Q
Lagrange Interpolation
A
- For each point
(xᵢ, yᵢ)
, create basis polynomialLᵢ(x)
- For each
Lᵢ(x)
, computeLᵢ(x) = ∏(j≠i) (x-xⱼ) / (xᵢ-xⱼ)
- Combine as
P(x) = ∑yᵢ·Lᵢ(x)
- Simplify the resulting polynomial
8
Q
Shamir’s Secret Sharing
A
- Choose secret
S
and thresholdk
- Create random polynomial
P
of degreek-1
withP(0) = S
- Compute
n
distinct points(i, P(i))
for participants - Distribute points to
n
participants - Any
k
participants can reconstruct using Lagrange interpolation
9
Q
Error Correction for Erasures
A
- Represent message as values of a polynomial
P(x)
- Transmit values at points
x₁,...,xₙ₊ₖ
- If
k
erasures occur, use remainingn
points - Apply Lagrange interpolation to recover original polynomial
- Extract message from
P(x)
10
Q
Berlekamp-Welch Algorithm for Error Correction
A
- Assume received values
rᵢ
at positionsxᵢ
- Create error locator polynomial
E(x)
of degreek
- Create
Q(x) = P(x)·E(x)
of degreen-1+k \ n4
. Set up system of n equations:Q(xᵢ) = rᵢ·E(xᵢ)
- Solve for coefficients of
Q
andE
- Compute
P(x) = Q(x) / E(x)
- Extract original message from
P(x)
11
Q
Cantor’s Diagonalization Proof
A
- Assume set S is countable
- List elements of S as s₁, s₂, s₃, …
- Construct element t that differs from sₙ in nth position
- Show t must be different from every element in the list
- Conclude t ∈ S but t is not in the enumeration
- This contradiction proves S is uncountable
12
Q
Constructing a Bijection between N and Z
A
- Define f: N → Z as follows:
- f(0) = 0
- For positive n, if n is odd: f(n) = (n+1)/2
- For positive n, if n is even: f(n) = -n/2
- This maps {0,1,2,3,4,5,…} to {0,1,-1,2,-2,3,…}
- Verify f is both injective and surjective
13
Q
Proving Set Equality
A
- Prove A ⊆ B: Show that if x ∈ A, then x ∈ B
- Prove B ⊆ A: Show that if x ∈ B, then x ∈ A
- Conclude A = B
14
Q
Constructing Truth Tables
A
- Identify all atomic propositions
- Create columns for each proposition and operator
- List all possible combinations of truth values
- Fill in truth values working from innermost to outermost operators
- Read final column for the truth value of the entire statement
15
Q
Method for Strong Induction Proof
A
- Establish base case(s): Prove P(0), P(1), etc. as needed
- State induction hypothesis: Assume P(0), P(1), …, P(k) all true
- Prove inductive step: Show P(k+1) follows from the hypothesis
- Conclude P(n) holds for all required n
16
Q
Finding Minimum Spanning Tree (Kruskal’s Algorithm)
A
- Sort all edges by weight (ascending)
- Start with empty graph T
- For each edge in sorted order:
a. If adding the edge creates a cycle, skip it
b. Otherwise, add the edge to T - Continue until T has n-1 edges (where n is number of vertices)
17
Q
Solving Linear Congruence ax ≡ b (mod m)
A
- Find gcd(a, m)
- If b is not divisible by gcd(a, m), no solution exists
- Otherwise, divide all terms by gcd(a, m) to get a’x ≡ b’ (mod m’)
- Find a⁻¹ (mod m’) using Extended Euclidean Algorithm
- Compute x ≡ a⁻¹·b’ (mod m’)
- Generate all solutions: x₀, x₀ + m’, x₀ + 2m’, …, x₀ + (gcd(a,m)-1)m’
18
Q
Chinese Remainder Theorem Implementation
A
- Given system x ≡ aᵢ (mod nᵢ) where all nᵢ are pairwise coprime
- Compute N = n₁·n₂·…·nₖ
- For each i, compute Nᵢ = N/nᵢ
- For each i, find Mᵢ where Mᵢ·Nᵢ ≡ 1 (mod nᵢ) using Extended Euclidean Algorithm
- Compute x ≡ ∑(aᵢ·Nᵢ·Mᵢ) (mod N)
19
Q
Applying Principle of Inclusion-Exclusion
A
- To find |A₁ ∪ A₂ ∪ … ∪ Aₙ|:
- Start with sum of individual set sizes: ∑|Aᵢ|
- Subtract all pairwise intersections: -∑|Aᵢ ∩ Aⱼ|
- Add back triple intersections: +∑|Aᵢ ∩ Aⱼ ∩ Aₖ|
- Continue alternating signs for larger intersections\n6. Final term is (-1)ⁿ⁺¹|A₁ ∩ A₂ ∩ … ∩ Aₙ|