Practice Generalization in CS Thinking

Use these practice problems to test your method after reviewing the concept explanation and worked examples.

Quick Recap

Generalization is the process of taking a pattern that appears in several examples and turning it into a rule or method that works in many cases. In computational thinking, it helps students move from one solved example to a reusable strategy.

Solve one case carefully, notice what stays the same, then write one rule that fits many cases.

Showing a random 20 of 80 problems.

Example 1

challenge
A hard-coded depth-first search uses a stack. A breadth-first search uses a queue. What single algorithm generalizes both?

Example 2

challenge
Conjecture: 'every odd number nโ‰ฅ3n \ge 3 is the sum of three primes.' Test for n=3,5,7,9,11n = 3, 5, 7, 9, 11 and state which case shows the conjecture must allow primes to repeat.

Example 3

medium
A specific check 'xโ‰ฅ18x \ge 18 AND xโ‰ค65x \le 65' was used for ages 18-65. Generalize this membership test for bounds aa and bb.

Example 4

challenge
Given f(1)=1,f(2)=2,f(3)=4,f(4)=8,f(5)=16f(1)=1, f(2)=2, f(3)=4, f(4)=8, f(5)=16, a student writes f(n)=2nโˆ’1f(n)=2^{n-1}. The actual rule counts regions formed by nn points on a circle joined by all chords, where f(6)=31f(6)=31. Why does 2nโˆ’12^{n-1} fail, and what does this show?

Example 5

medium
From `T(1)=1, T(2)=3, T(3)=6, T(4)=10`, what closed-form rule for T(n)T(n) generalizes the pattern?

Example 6

medium
From f(0)=1,f(1)=2,f(2)=4,f(3)=8f(0)=1, f(1)=2, f(2)=4, f(3)=8, what general rule fits, and how would you verify it in code?

Example 7

hard
A student sees that n=1,2,3,4n=1,2,3,4 all give n2โ‰ฅnn^2 \ge n and concludes 'square is always at least the number itself.' For which real numbers nn does this fail?

Example 8

medium
From g(1)=2g(1)=2, g(2)=5g(2)=5, g(3)=10g(3)=10, g(4)=17g(4)=17, find a general rule.

Example 9

easy
To greet any user, the messages were 'Hi Ann', 'Hi Bob', 'Hi Cy'. Generalize the message for a name xx.

Example 10

hard
Outputs for inputs 1, 2, 3, 4, 5 are 2, 6, 12, 20, 30. Find a general rule.

Example 11

easy
From h(1)=4h(1)=4, h(2)=7h(2)=7, h(3)=10h(3)=10, find a general rule for h(n)h(n).

Example 12

easy
Cubes: side 1 has volume 1, side 2 has volume 8, side 3 has volume 27. Generalize for side ss.

Example 13

medium
From 22=42^2=4, 23=82^3=8, 24=162^4=16 a student writes 2n2^n. What general rule covers the product 2aโ‹…2b2^a \cdot 2^b?

Example 14

hard
A bubble sort, an insertion sort, and a selection sort all sort lists in O(n2)O(n^2). What's the danger of over-generalizing them into 'they're all the same'?

Example 15

hard
A web framework has hand-written handlers for `/user/1/posts`, `/user/2/posts`, etc. Generalize to a single route pattern and handler.

Example 16

easy
A function gives g(0)=1g(0)=1, g(1)=3g(1)=3, g(2)=5g(2)=5, g(3)=7g(3)=7. What general rule fits?

Example 17

hard
From a specific check 'string of length 5 has 5 indices, 0 to 4' generalize to any string of length nn and state the valid index range.

Example 18

easy
A snack pack has 4 cookies. With 1 pack you have 4 cookies, with 2 packs 8, with 3 packs 12. Generalize for pp packs.

Example 19

medium
A program multiplies a list by a constant: [1,2,3]โ†’[3,6,9][1,2,3]\to[3,6,9] used factor 3. Generalize the output for factor cc and element xx.

Example 20

medium
From f(2)=7,f(3)=10,f(4)=13f(2)=7, f(3)=10, f(4)=13, write a rule and predict f(10)f(10).