Unit 8 · Lesson 3

Unreasonable Time

When does an algorithm take so long it's practically impossible to run?

FRQ

Last Lesson Recap

In our last lesson we compared two search algorithms. What makes binary search more efficient than linear search?

Today's Activity

Two problems that seem familiar but are a bit harder to solve.

We already found algorithms for checking whether a specific ticket number was in a list.

Today we change the question: we want to find combinations of tickets rather than a single one.

As we work, pay attention to how many "checks" each new algorithm requires.

The big question: do those check counts grow at a reasonable or unreasonable rate?

Activity — Regular Raffle

The Problem

The Regular Raffle

The winner is the one ticket whose number exactly matches the winning number.

Do This

Scan the QR code on your phone to receive your ticket number. Once everyone has a number, see whether anyone has the one winning ticket.

Activity — Pair Raffle

The Problem

The Pair Raffle

The winners are any two tickets whose numbers add up to the winning sum.

Do This

Using the same ticket numbers from the regular raffle, work together to figure out whether any pair of tickets adds up to the winning sum.

Activity — Group Raffle

The Problem

Find any group of tickets that adds to the winning number.

Group Raffle

The winners are any group of tickets (from one up to all of them) whose numbers add up to the winning sum.

Do This

Using the same ticket numbers from the pair raffle, now try to find a group of any size (one ticket, two, three, or all of them) whose numbers sum to the winning number. Work together to search for a winning group.

Partner Activity

Let's count the checks.

Do This

With your partner, fill in both tables on your activity guide. For each number of tickets, count how many checks your algorithm would need to make in the worst case.

For the pair raffle, count each distinct two-ticket pair. For the group raffle, count the groups of any size (from one to all).

Hint for pairs: if you have tickets A, B, C, the pairs are AB, AC, and BC. Try drawing lines between the tickets to count them.

Pair Raffle
TicketsChecks
2?
3?
4?
5?
8?
Group Raffle
TicketsChecks
2?
3?
4?
5?
8?
Pair Raffle — Results

Tickets vs. Checks

Tickets (n)Pair Checks
21
33
46
510
828

The Pattern

The number of checks grows faster than the number of tickets. Adding one more ticket always adds more new pairs than the last ticket did.

Formula

The exact relationship is (n² − n) / 2. Because of the term, this curve bends upward. Algorithms with an n² term are called polynomial.

Pair Raffle — Checks vs. Tickets

1 4 8 tickets 0 10 20 28 checks
Group Raffle — Results

Tickets vs. Checks

Tickets (n)Group Checks
23
37
415
531
8255

The Pattern

Each additional ticket more than doubles the number of checks. The values (3, 7, 15, 31, 63, 127, 255) are each one less than a power of 2.

Formula

The exact relationship is 2n − 1. Because of the 2n term, this curve bends upward extremely fast. Algorithms with a 2n term are called exponential.

Group Raffle — Checks vs. Tickets

1 4 8 tickets 0 127 255 checks
Group Raffle — Another Way to Think About It

Each ticket is a flap on a flippy-do.

When every flap is showing 1, the total value is the number of checks you need. Think of each ticket as a binary place value.

Tickets (n)Group ChecksAs binary
1 1 1
2 3 11
3 7 111
4 15 1111
5 31 11111
8 255 11111111

Key Insight

The number of group-raffle checks is always the largest number you can make with that many bits when every bit is 1. That is exactly 2n − 1.

Every flap is a 1: flip them all to find the total checks.

1 ticket:
1
1
= 1 = 1 check
2 tickets:
2
1
1
1
= 2+1 = 3 checks
4 tickets:
8
1
4
1
2
1
1
1
= 8+4+2+1 = 15 checks
8 tickets:
128
1
64
1
32
1
16
1
8
1
4
1
2
1
1
1
= 128+64+32+16+8+4+2+1 = 255 checks
FRQ — Discussion

Both curves go up. Why is only one unreasonable?

Both polynomial (pair raffle) and exponential (group raffle) curves bend upward as n grows. Why do you think only exponential is considered to run in an unreasonable amount of time?

Pair Raffle — Polynomial

Checks grow as roughly . Doubling the tickets quadruples the work. That is a lot, but a faster computer or some optimization might still make it feasible.

Group Raffle — Exponential

Checks grow as 2n. Adding just one more ticket doubles all the work. Even the fastest computers cannot keep up once n gets large.

Activity — Reasonable or Unreasonable?

Watch the algorithms count up.

Do This

Set n with the slider and press Start. The app simulates each algorithm working through its checks at the same pace. Discuss with a partner: which algorithms still seem reasonable as n grows?

Try n = 10, then n = 20, then n = 25. What changes?

n = 10
Sorted Raffle log₂(n) steps
Normal Raffle n steps
Pair Raffle n² steps
Group Raffle 2n steps
Summary

Reasonable or Unreasonable?

Polynomial — Reasonable

Algorithms whose check count grows as a polynomial power of n (constant, linear, n², n³, etc.) run in reasonable time. They can be slow for large n, but a faster computer or better implementation can still make progress.

Sorted Raffle (logarithmic): reasonable.
Normal Raffle (linear): reasonable.
Pair Raffle (polynomial n²): reasonable.

Exponential — Unreasonable

Algorithms whose check count grows as an exponential (2n, 3n, etc.) or factorial run in unreasonable time. Even with the fastest computers imaginable, adding one more item to the input can make the algorithm take exponentially longer to complete.

Group Raffle (exponential 2n): unreasonable.

Note: the line between reasonable and unreasonable is drawn at polynomial versus exponential — not at any specific number of steps.

Comparison — All Four Algorithms

How fast do the checks grow?

Tickets (n) Sorted Raffle
log2(n) — reasonable
Normal Raffle
n — reasonable
Pair Raffle
n2 — reasonable
Group Raffle
2n — unreasonable
10 4 10 100 1,024
20 5 20 400 1,048,576
100 7 100 10,000 1.27 × 1030
1,000 10 1,000 1,000,000 1.07 × 10301
10,000 14 10,000 100,000,000 2.00 × 103010

By n = 1,000 the group raffle requires roughly 10301 checks. The observable universe contains an estimated 1080 atoms: the algorithm needs far more checks than that, and no amount of faster hardware changes this.

MCQ

Check for Understanding

An algorithm processes a list of n items. As n doubles, the number of steps the algorithm takes roughly quadruples. What best describes this algorithm?

  • A Logarithmic: it runs in reasonable time.
  • B Linear: it runs in reasonable time.
  • C Polynomial: it runs in reasonable time.
  • D Exponential: it runs in unreasonable time.
Wrap Up — Key Vocabulary
Polynomial Efficiency
An algorithm runs with polynomial efficiency when the number of steps grows as a polynomial power of the input size: constant, linear, quadratic (n²), cubic (n³), and so on. These algorithms are said to run in reasonable time. The pair raffle (checking every pair of tickets) is an example.
Exponential Efficiency
An algorithm runs with exponential efficiency when the number of steps grows as an exponential function of the input size: 2n, 3n, and so on. These algorithms are said to run in unreasonable time because the number of steps becomes astronomically large even for small increases in n. The group raffle (checking every subset of tickets) is an example.
Reasonable vs. Unreasonable Time
An algorithm is considered to run in reasonable time if its efficiency is polynomial or better. An algorithm that requires exponential or factorial time is considered to run in unreasonable time: no practical computer could complete it for large inputs, regardless of how fast the hardware becomes.