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
mediumA function returns `arr[len(arr) / 2]` as median. For even length, what is wrong?
Example 2
easyWhat edge case might break a function `divide(a, b)` returning ?
Example 3
challengeYou 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
mediumA loop `for i in 0..n` accesses `arr[i+1]`. At what index does it overflow?
Example 5
hardQuicksort with first-element pivot: name two adversarial inputs that turn its expected into worst-case .
Example 6
hardA login system rejects passwords chars. What attacker-relevant edge case might still slip in?
Example 7
mediumA `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
mediumA field expects an ASCII string but receives an emoji. What kind of edge case is this?
Example 9
mediumFloating-point: which two non-finite values should a numerical function explicitly handle as edge cases?
Example 10
hardA recursive `factorial(n)` uses base `if n == 1`. What edge input breaks it?
Example 11
mediumIn a date-handling library, name one calendar edge case besides leap years.
Example 12
easyA function expects a non-empty list. Passing `[]` is a(n) ___ edge case.
Example 13
easyFor a function that takes a positive integer, what is the smallest valid value to test?
Example 14
mediumA pseudocode function `factorial(n)` returns if else . Why is an edge case rather than a 'normal' input?
Example 15
mediumA function reads lines from a file. List two file-existence edge cases and two file-content edge cases worth testing.
Example 16
hardA graph BFS function expects no self-loops. What three structural edge cases should you test even so?
Example 17
easyA list-indexing function accepts indices 0 to n-1. Which index is the upper-boundary edge case?
Example 18
mediumA function `maxOf(list)` is correct for lists of size but you never tested size 1. Why is the single-element list a meaningful edge case?
Example 19
hardA hash table doubles its bucket count when load factor exceeds . What edge case occurs precisely at the resize boundary?
Example 20
mediumA function returns the median of a list. Which list size and content is a key edge case?