Discrete Math for Data Science

DSCI 220, 2025 W1

November 17, 2025

Announcements

Warm-Up: Multiplication Rule

Question:
What happens to the number of rows in a DataFrame when we use pandas.melt()?

Visualizing Wide to Long

Before melting (wide format):

 

 

 

After melting (long format):

 

 


  • Each wide row expands into three long rows — one for each temperature.
  • Each pair (Object, Temperature) is one combination—just like the outfits we counted last time.
  • The total number of rows = 4 objects × 3 temperatures = 12 outcomes.

Visualizing the Mapping Change

Before melting:

We have a function that maps each Object to a tuple of states across temperatures:

\[ f:\ \text{Object} \to (\text{Cold},\ \text{Warm},\ \text{Hot}) \]

Example: \[ f( \text{Wicked Witch}) = ( \text{fine}, \text{dripping}, \text{gone?}) \]

After melting:

We redefine the function so that the pair (Object, Temperature) is the input:

\[ g: ( \text{Object}, \text{Temperature}) \to \text{State} \]

Example: \[g( \text{Wicked Witch}, \text{Warm}) = \text{dripping} \]

The input domain has expanded from Objects to Objects × Temperatures. Each input now produces a single scalar output instead of a vector.

This is why the melted data get longer — we’ve made all combinations explicit.

How Melting Affects Data Size

When we melt data, we don’t add new information — we just make existing information longer and more explicit.

Format Shape Description
Wide (4, 4) One row per object; columns for Cold, Warm, Hot
Long (Melted) (12, 3) One row for each (Object, Temperature) pair

Effect: The number of rows increases by a factor equal to the number of melted columns.
Each object’s name and each temperature label are now repeated multiple times.

Memory tradeoff: Long data are larger in memory but easier to work with for grouping and plotting.

A New Counting Challenge

 

Arrange 4 people around a table.

Question:
How many different ways can the people be seated?

Discuss:

  • What counts as a different arrangement?
  • What information defines one arrangement?

Observing the Structure

Let’s agree on a model for our table:

Seat 1 Seat 2 Seat 3 Seat 4
? ? ? ?
Each arrangement can be described as a 4-tuple:
(Who’s in seat 1, Who’s in seat 2, Who’s in seat 3, Who’s in seat 4)

 

Our model is the set of all possible 4-tuples with no repeats.

Building an Arrangement

How many choices do we have for each chair?

  1. Seat 1: 4 choices
  2. Seat 2: 3 remaining
  3. Seat 3: 2 remaining
  4. Seat 4: 1 remaining

\(\text{Total} = 4 \times 3 \times 2 \times 1 = 24\) arrangements

That’s the multiplication rule — just like outfits, but now the choices depend on previous ones.

Permutations

A permutation is an arrangement of \(n\) distinct objects in a specific order.

  • Order matters — changing the order creates a new permutation.
  • Each permutation corresponds to a unique sequence of choices from the set.

If there are \(n\) distinct objects, then the number of permutations is:

\[ P(n) = n! = n \times (n-1) \times (n-2) \times \dots \times 1 \]

Example: Four people can sit in a row in

\[ P(4) = 4! = 24 \]

different ways.

Counting under rotation

Embrace the fact that the table is round.

 

For any rotation, the group of people is sitting in the same relative order.

For each arrangement there are 4 equivalent. Thus we ______________ the total by ______________.

 

Alternatively we can fix one person’s seat.
Then the remaining 3 can be arranged freely around the table.

 

Total distinct circular seatings: \((4 − 1)! = 6\).

Friendship Bracelets

 

Given: 20 beads, each a different color. Make a circular bracelet by threading all 20 beads.

20-bead bracelet Twenty differently colored beads arranged in a circle.

Question:
How many different bracelets can be made?

Choosing a Committee

Goal: From 8 people, form a 3-person committee.

 

Question:
How many different committees could we form?

 

Discuss:

  1. Consider it a sequence of 3 choices
  2. Which of those describe the same committee?
  3. How can we apply what we learned about rotations?

From Choices to Combinations

Model our 3-person committee.

If we make choices one at a time:

\[ 8 \times 7 \times 6 = 336 \]

That counts every possible order of picking 3 people.

But a committee doesn’t have an order — each group of 3 appears \(3! = 6\) times, once for every possible order.

So the number of distinct committees is:

\[ \frac{8 \times 7 \times 6}{3!} = 56 \]

Combinations

A combination is a selection of \(k\) objects from \(n\) where order does not matter.

  • The group \(\{A, B, C\}\) is the same as \(\{B, A, C\}\).
  • Each combination represents a unique set of choices.

If there are \(n\) objects and we choose \(k\) of them, the number of distinct combinations is:

\[ C(n, k) = \binom{n}{k} = \frac{n!}{k!(n-k)!} \]

Example: Choosing a 3-person committee from 8 people:

\[ C(8, 3) = \frac{8!}{3!5!} = 56 \]

Note: Each committee is a subset of the 8 people — we ignore order, only membership matters.

Reflection

Compare the models:

Scenario Model Outcome Count
Outfits (shoe, pant, shirt) \(|S|\times|P|\times|H|\)
Seating (seat 1, seat 2, seat 3, seat 4) \(4\times 3\times 2\times 1\)
Circular Seating (fix one person) \((4 − 1)! = 6\)
Choosing Guests {subset of guests} \(\binom{4}{k}\)
  • All start by modeling the outcomes carefully before counting.
  • The model determines whether order matters.

Challenge: Putting It All Together

There are 8 people, and 4 seats at the round table.

Question: How many distinct arrangements are possible if rotations and reflections count as the same?

Communicate: Explain each step of your reasoning.

Generalize: What if there are \(n\) people and \(k\) seats?

Summary

Concept Order Matters? Model Ex Count
Permutation Yes Ordered arrangement 4! = 24
Combination No Unordered selection \(\binom{4}{2} = 6\)

Punchline:
Counting always starts with modeling the outcomes.
Once we know what counts as “different,” the computation follows.