Skip to content
Computer Science · Grade 11

Active learning ideas

Iterative vs. Recursive Solutions

Active learning works for this topic because comparing iterative and recursive solutions requires hands-on experimentation with code, runtime, and memory usage. Students need to see, touch, and feel the differences through debugging and testing to grasp why one approach might be chosen over the other. The contrast between the two methods becomes clearest when students implement both and observe outcomes directly.

Ontario Curriculum ExpectationsCS.HS.A.2CS.HS.A.5
25–45 minPairs → Whole Class4 activities

Activity 01

Formal Debate30 min · Pairs

Pair Programming: Factorial Duel

Pairs implement factorial iteratively with a loop and recursively with a base case. They trace both on paper for n=5, then run in an IDE to compare execution time and stack trace. Pairs swap codes to identify improvements.

Differentiate between the memory usage patterns of iterative and recursive algorithms.

Facilitation TipDuring Pair Programming: Factorial Duel, have students alternate roles every 5 minutes to keep both partners engaged in tracing and comparing approaches.

What to look forPresent students with two code snippets, one iterative and one recursive, solving the same problem (e.g., summing numbers from 1 to n). Ask them to identify which is which, and write one sentence explaining the primary difference in how they achieve the result.

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

Activity 02

Formal Debate45 min · Small Groups

Small Groups: Fibonacci Face-Off

Groups code iterative and recursive Fibonacci functions, input large values like n=40, and observe recursion's stack overflow. They graph recursion depth versus input size and discuss efficiency trade-offs.

Analyze scenarios where an iterative solution is clearly superior to a recursive one, and vice-versa.

Facilitation TipFor Small Groups: Fibonacci Face-Off, provide a shared debugging environment so students can pause execution and visualize stack frames together.

What to look forProvide students with a problem description (e.g., calculating the nth number in a sequence). Ask them to write down: 1. The base case for a recursive solution. 2. The loop condition for an iterative solution. 3. One reason they might choose iteration over recursion for this problem.

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

Activity 03

Formal Debate35 min · Whole Class

Whole Class: Scenario Debates

Display 6 problems on screen, like summing arrays or parsing JSON. Class votes iterative or recursive, then justifies in pairs before full debate. Tally results and code winning approaches.

Justify the choice between an iterative and recursive approach for a specific problem.

Facilitation TipIn Whole Class: Scenario Debates, assign roles (e.g., 'recursion advocate,' 'iteration advocate') to push students to articulate trade-offs clearly.

What to look forFacilitate a class discussion: 'Imagine you are building a program to search through a deeply nested folder structure on a hard drive. What are the potential advantages and disadvantages of using a recursive approach versus an iterative approach for this task? Consider memory usage and code clarity.'

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

Activity 04

Formal Debate25 min · Individual

Individual: Tree Traversal Challenge

Students code iterative and recursive in-order tree traversals on a shared binary tree diagram. They simulate memory usage by drawing stack frames and loop states, then verify outputs.

Differentiate between the memory usage patterns of iterative and recursive algorithms.

Facilitation TipDuring Individual: Tree Traversal Challenge, require students to submit both methods with runtime measurements to ground their analysis in data.

What to look forPresent students with two code snippets, one iterative and one recursive, solving the same problem (e.g., summing numbers from 1 to n). Ask them to identify which is which, and write one sentence explaining the primary difference in how they achieve the result.

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

A few notes on teaching this unit

Teach this topic by starting with small, familiar problems like factorials or sequences, where students can easily trace iterations and recursive calls. Avoid abstract explanations about time complexity at first; instead, let students measure runtime and memory themselves. Research shows that concrete examples and immediate feedback reduce confusion about recursion’s overhead. Emphasize that iteration is often simpler for beginners, but recursion shines in problems with natural subdivisions, like tree traversals.

Students will confidently implement both iterative and recursive solutions for the same problem and explain trade-offs in time, space, and readability. They will use debugging tools to trace execution and justify their choice of method based on problem constraints. By the end, they will recognize when recursion is appropriate and when iteration is safer.


Watch Out for These Misconceptions

  • During Pair Programming: Factorial Duel, watch for students assuming recursion is always faster without testing both versions.

    Have pairs run both solutions on large inputs (e.g., factorial(10000)) and compare runtimes. Guide them to notice that recursion’s function call overhead slows it down, while iteration handles large inputs smoothly.

  • During Small Groups: Fibonacci Face-Off, watch for students believing recursive solutions use the same memory as iterative ones.

    Use the debugger to pause execution and show the growing stack frames in the recursive version. Ask students to count the number of active calls at the deepest point to visualize memory accumulation.

  • During Whole Class: Scenario Debates, watch for students assuming any problem can be solved recursively without issues.

    Introduce a problem with deep nesting (e.g., a binary tree with 1000 levels) and have groups attempt a recursive solution. When their code crashes, prompt them to rewrite it iteratively using a stack to see the practical limitations of recursion.


Methods used in this brief