Practice Edge Cases in CS Thinking

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

Quick Recap

Edge cases are unusual or boundary inputs that sit at the limits of what a program is expected to handle. They often reveal bugs that do not appear in ordinary examples.

If normal inputs show whether the code works, edge cases show whether it is truly robust.

Showing a random 20 of 80 problems.

Example 1

medium
A function returns `arr[len(arr) / 2]` as median. For even length, what is wrong?

Example 2

easy
What edge case might break a function `divide(a, b)` returning a/ba/b?

Example 3

challenge
You must enumerate the COMPLETE set of boundary inputs to test a function `clamp(x, lo, hi)` for correctness of its comparisons. List the distinct relative positions of x that fully cover the boundaries.

Example 4

medium
A loop `for i in 0..n` accesses `arr[i+1]`. At what index does it overflow?

Example 5

hard
Quicksort with first-element pivot: name two adversarial inputs that turn its expected O(nlogโกn)O(n \log n) into worst-case O(n2)O(n^2).

Example 6

hard
A login system rejects passwords >64> 64 chars. What attacker-relevant edge case might still slip in?

Example 7

medium
A `sum_positive(nums)` function should sum only positive numbers in a list. Identify three edge-case inputs whose behavior must be explicitly tested.

Example 8

medium
A field expects an ASCII string but receives an emoji. What kind of edge case is this?

Example 9

medium
Floating-point: which two non-finite values should a numerical function explicitly handle as edge cases?

Example 10

hard
A recursive `factorial(n)` uses base `if n == 1`. What edge input breaks it?

Example 11

medium
In a date-handling library, name one calendar edge case besides leap years.

Example 12

easy
A function expects a non-empty list. Passing `[]` is a(n) ___ edge case.

Example 13

easy
For a function that takes a positive integer, what is the smallest valid value to test?

Example 14

medium
A pseudocode function `factorial(n)` returns 11 if n=0n=0 else nโ‹…factorial(nโˆ’1)n \cdot \text{factorial}(n-1). Why is n=0n=0 an edge case rather than a 'normal' input?

Example 15

medium
A function reads lines from a file. List two file-existence edge cases and two file-content edge cases worth testing.

Example 16

hard
A graph BFS function expects no self-loops. What three structural edge cases should you test even so?

Example 17

easy
A list-indexing function accepts indices 0 to n-1. Which index is the upper-boundary edge case?

Example 18

medium
A function `maxOf(list)` is correct for lists of size โ‰ฅ2\ge 2 but you never tested size 1. Why is the single-element list a meaningful edge case?

Example 19

hard
A hash table doubles its bucket count when load factor exceeds 0.750.75. What edge case occurs precisely at the resize boundary?

Example 20

medium
A function returns the median of a list. Which list size and content is a key edge case?