Discrete Math for Data Science

DSCI 220, 2025 W1

October 6, 2025

Announcements

Modular Arithmetic

Modular Arithmetic

Definition: \(a \equiv b \pmod m \iff m \mid (a-b)\)

If \(a \equiv b \pmod m\) and \(c \equiv d \pmod m\), then:

  • Addition: \(a + c \equiv b + d \pmod m\)
  • Subtraction: \(a - c \equiv b - d \pmod m\)
  • Multiplication: \(ac \equiv bd \pmod m\)
  • Exponentiation: for any integer \(n \ge 0\), \(a^{n} \equiv b^{n} \pmod m\)

Reduce anytime: reduce intermediate results mod \(m\) at any step.

Caution (division): “Division” is only valid when a modular inverse exists.
\(\gcd(a,m)=1\Rightarrow a^{-1}\) exists, and \(ax \equiv b \pmod m \Rightarrow x \equiv a^{-1}b \pmod m\).

Caution (exponents): From \(a\equiv b \pmod m\) you may raise the bases: \(a^n\equiv b^n\), but in general \(c^{a}\not\equiv c^{b}\pmod m\).

Inverse \(\bmod m\)

When does a number \(a\) not have an inverse \(\bmod m\)?

Consider \(5x \bmod 12\):

Consider \(9x \bmod 12\):

 

A number \(a\) has an inverse \(\bmod m\) iff \(\gcd(a,m)= 1\).

Linear Congruences

 

Solve:

  • \(9x\equiv 1\pmod{26}\)

 

 

  • \(9x\equiv 5\pmod{26}\)

Big Powers Fast

 

Pick one:

  • \(2^{1000}\pmod 7\)
  • \(3^{12345}\pmod{10}\)
  • \(5^{2024}\pmod{13}\)

Two Dials

Find \(t\pmod {15}\) such that
\(t\equiv 2\pmod 3\) and \(t\equiv 1\pmod 5\).

05:00

Asymptotics

Functions

Math: a function is a mechanism for translating items from one collection to another.

 

\(f: A\to B\)


Our current interest is quantifying the way that functions grow.

Functions for Data Science

 

Functions as costs:

  1. generally non-negative.

  2. generally non-decreasing with size of input.

Sketch:

Asymptotic Upper Bounds

A function \(f(n) = O(g(n))\) iff there are positive constants \(c\) and \(n_0\) such that \(f(n)\leq c\cdot g(n)\) for any \(n\geq n_0\).

 

Big O Proof

Prove that \(3n^2 + 7n + 2 = O(n^2)\).


Defn: … there are positive constants \(c\) and \(n_0\) such that \(f(n)\leq c\cdot g(n)\) for any \(n\geq n_0\).

 

 

 

 

Therefore, \(c=\)____ and \(n_0=\)____ witness the claim.

Big O Strategy

Goal. To prove \(f(n)=O(g(n))\), show there exist constants \(c>0\) and \(n_0\) such that
for all \(n\ge n_0\), \(f(n)\le c\,g(n)\).

  1. Pick your region.
    Choose \(n_0\) where simple comparisons are true (e.g., for \(n\ge 1\), \(n^2\ge n\); for \(n\ge e\), \(\log n\ge 1\)).

  2. Dominate each term by \(g(n)\).
    On \(n\ge n_0\), bound every term of \(f\) by a constant multiple of \(g\):
    \(f(n)=\text{(term}_1)+\dots+\text{(term}_k)\ \le\ a_1 g(n)+\dots+a_k g(n)\).

  3. Add and name the constant.
    Sum the multipliers: \(f(n)\le (a_1+\cdots+a_k)\,g(n)\).
    Set \(c=a_1+\cdots+a_k\).

  4. State the line that matters.
    “For all \(n\ge n_0\), \(f(n)\le c\,g(n)\). Therefore \(f(n)=O(g(n))\).”