Skip to content
Computer Science · Grade 12

Active learning ideas

Recursion vs. Iteration

Active learning works well for recursion versus iteration because students often struggle to see the difference between the two approaches without hands-on practice. Implementing both methods for the same problem helps them internalize trade-offs in time, space, and readability. When students write, test, and compare their own code, misconceptions about speed and elegance become clear.

Ontario Curriculum ExpectationsCS.P.16CS.AA.6
20–45 minPairs → Whole Class4 activities

Activity 01

Formal Debate35 min · Pairs

Pair Programming: Factorial Duel

Pairs write recursive and iterative factorial functions in Python. They add timing code with time module and test with inputs from 1 to 10000, noting failures or slowdowns. Pairs graph results and present one key insight to the class.

Compare the memory footprint of recursive and iterative solutions for the same problem.

Facilitation TipDuring Pair Programming: Factorial Duel, circulate to ensure both partners write and test their code independently before comparing results.

What to look forPresent students with two code snippets: one recursive and one iterative, both solving the same problem (e.g., calculating the sum of numbers from 1 to n). Ask them to identify which is which, and then write down one advantage of the iterative version and one advantage of the recursive version.

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

Activity 02

Formal Debate45 min · Small Groups

Small Group Challenge: Fibonacci Face-Off

Groups of three implement recursive, iterative, and memoized recursive Fibonacci solutions. They draw call stack diagrams for small n values and run benchmarks on large inputs. Groups compare space usage via recursion depth limits and discuss preferences.

Explain scenarios where an iterative solution might be preferred over a recursive one.

Facilitation TipIn the Small Group Challenge: Fibonacci Face-Off, provide printed stack diagrams to help groups visualize recursive calls and spot missing base cases.

What to look forPose the question: 'Imagine you are designing a system to parse a deeply nested XML document. Would you lean towards a recursive or iterative solution, and why? Consider potential issues like document size and system stability.'

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

Activity 03

Formal Debate25 min · Whole Class

Whole Class Debate: Real-World Scenarios

Project five problems like binary search trees or matrix traversal. Class votes on recursive versus iterative, then justifies in full-group discussion with whiteboard sketches. Tally preferences and analyze class consensus against performance norms.

Design both a recursive and an iterative solution for a given problem and analyze their complexities.

Facilitation TipFor the Whole Class Debate: Real-World Scenarios, assign roles to ensure every student contributes an argument for either recursion or iteration during the discussion.

What to look forAsk students to write down a scenario where recursion is a more natural fit than iteration, and a scenario where iteration is clearly superior. For each scenario, they should briefly explain their reasoning, touching on factors like code clarity or performance.

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

Activity 04

Formal Debate20 min · Individual

Individual Analysis: Custom Problem

Students select a problem like power calculation or string reversal. They code both versions, compute Big O notations, and write a one-page justification for the better choice under memory constraints. Submit for peer review.

Compare the memory footprint of recursive and iterative solutions for the same problem.

Facilitation TipDuring the Individual Analysis: Custom Problem, remind students to include complexity analysis in their write-ups to connect code to theory.

What to look forPresent students with two code snippets: one recursive and one iterative, both solving the same problem (e.g., calculating the sum of numbers from 1 to n). Ask them to identify which is which, and then write down one advantage of the iterative version and one advantage of the recursive version.

AnalyzeEvaluateCreateSelf-ManagementDecision-Making
Generate Complete Lesson

A few notes on teaching this unit

Teachers should start with small, familiar problems like factorial before moving to Fibonacci, since factorial is simpler for students to grasp. Emphasize tracing code on paper to build intuition, and avoid jumping straight to optimizations. Research shows students benefit from seeing multiple representations, so pair tracing with timing measurements to ground abstract concepts in observable data.

Students will implement recursive and iterative solutions for factorial and Fibonacci problems with correct base cases and loop conditions. They will compare execution times and memory usage, then justify which approach fits a given problem. By the end, students can explain when each method is preferable in terms of complexity and clarity.


Watch Out for These Misconceptions

  • During Pair Programming: Factorial Duel, watch for students assuming recursion runs faster because it feels more elegant.

    Have partners measure and plot execution times for both solutions using built-in timing functions, then discuss why the iterative version is often faster despite the recursive version’s readability.

  • During Small Group Challenge: Fibonacci Face-Off, watch for groups overlooking stack overflow when testing large inputs.

    Ask each group to intentionally test their recursive Fibonacci with n = 1000, observe the stack overflow error, and then revise their code to include a base case that prevents deep recursion.

  • During Whole Class Debate: Real-World Scenarios, watch for students dismissing iteration as less elegant for complex problems.

    Provide a recursive-to-iterative conversion worksheet during the debate, and ask groups to translate a recursive tree traversal into an iterative version using an explicit stack, highlighting how iteration can match recursion’s clarity.


Methods used in this brief