Exploring the question of teaching recursion or iterative control structures first

March 9, 2018 at 7:00 am 9 comments

Someone raised the question on the SIGCSE Members list: Which should we teach first, iteration or recursion?

I offered this response:

The research evidence suggests that one should teach iterative control structures before recursion, IF you’re going to teach both.  If you are only going to teach one, recursion is easier for students.  If you teach recursion first, the evidence (Kessler & Anderson, 1986; Wiedenbeck, 1989) suggests that it becomes harder to learn the iterative control structures.

The push back I got was, “Surely, we have better data than 30 year old studies?!?”  Here was my reply:

I agree that it would be great to do these studies again.  Given that we have an experiment and a successful replication, it could be an MS or advanced undergrad project to replicate one of those earlier experiments.

For myself, I don’t expect much difference.  As you say, student brains have stayed the same.  While the languages have changed, the basic iterative control structures (for, while, repeat) haven’t changed much in modern languages from what they were in C and even Pascal.  Curriculum may be a factor, and that would be interesting to explore.

Two directions that I think would be great to explore in this space:

(1) The Role of Block-Based Languages: As you say, the previous research found that iterative control structures are syntactically complicated for novices.  But multiple studies have found that block-based iterative structures are much easier for novices than text-based versions.  What if we went recursion->block iteration->text iteration?  Would that scaffold the transition to the more complicated text-based iterative control structures?

(2) The Role of High-Level Functions: I don’t know of any studies exploring high-level functions (like the ones that Kathi Fisler used to beat the Rainfall Problem, or even map/reduce/filter) in the development of understanding of recursion and iterative control structures.  High-level functions have a fixed form, like for/repeat/while, but it’s a simpler, functional form.  Could we teach high-level functions first, to lead into recursion or iterative control structures?  Or maybe even teach recursion or iterative control structures as two different ways of implementing the high-level functions?

In general, there are too many questions to explore and too few people asking these questions with empirical data. We might rely on our teaching experience to inform our answers to these questions, but as Neil Brown showed us (see CACM Blog post this month that talks about this result), higher-education CS teachers are actually way off when it comes to estimating what students find hard.

SIGCSE-Members, please consider asking some of these questions on your campus with your students. There are well-formed questions here that could be answered in a laboratory study that could be encapsulated in a single semester.  The students will get the opportunity to do empirical research with humans, which is a useful skill in many parts of computing.

Entry filed under: Uncategorized. Tags: , , , .

The state of the field in pre-college computer science education: Highly recommended Google report Announcing Barbara Ericson’s Defense on Effectiveness and Efficiency of Parsons Problems and Dynamically Adaptive Parsons Problems: Next stop, University of Michigan

9 Comments Add your own

  • 1. Alfred Thompson  |  March 9, 2018 at 10:37 am

    OK this will probably get me jumped on but just how important is recursion? As a way of doing iteration it seems awfully complicated and error prone compared to iterative control structures. Sure there are applications where recursion is the best if not the only way to solve some problems but can’t it wait until a second or third course?

    When we ask about projects that required recursion for beginners there are few good examples. Towers of Hanoi for example. Even Fibonacci is just as easily solved using iteration as recursion. Exploring trees? Sure. We do that in AP CS but at the HS level at least that is usually a second or third course.

    Not teaching iterative control structures would be a huge mistake and if the evidence suggests it is better to teach that first if we are going to teach both the decision seems easy.

    Reply
    • 2. Mike Zamansky  |  March 9, 2018 at 11:42 am

      With CS4All and K12 on the table it becomes an even more interesting conversation.

      My take on the normal intro courses taught in high school as that they’re supposed to serve two purposes at the same time. They are supposed to give you the basic core knowledge that an educated person should have and also possibly pique a student’s interest and set the stage for more advanced study.

      If we’re talking about that type of intro course then you have to ask a few questions:

      1. Is it beneficial to introduce recursion early for students who’ll go further.
      2. Is it beneficial for those who won’t go on
      3. If it is beneficial to one group but not the other, can it be done so as not to do harm to the other group.

      It’s also worth looking at recursion away from the computer, call stack, etc. We’re really talking about taking a problem, biting off a piece and handling it and then repeating the process with what’s left until we’re done.

      From a higher level point of view, that’s recursion and it’s also a model for how we do lots of things.

      We do list processing – to do lists in that manner:

      1. do the first thing
      2. remove it from the list and repeat

      but repeat can be seen as recurse.

      I go back and forth on this issue. I think scheme and recursion first works at Stuy but am not convinced it’s right all the time.

      Reply
  • 3. gasstationwithoutpumps  |  March 9, 2018 at 6:15 pm

    I’ve never been a fan of recursion first. I think that with iterations like “for x in container:” (to pick a python example), iteration is now much easier to teach first, as we don’t need to be explicit about incrementing and ordering (just not changing the contents of the container inside the loop).

    Reply
  • […] issue is like the question of recursion-first or iterative-control-structures-first. (See this earlier blog post.) If your students don’t have to learn iterative control structures, then teach recursion-only. […]

    Reply
  • 5. Mark Lewis  |  June 13, 2018 at 3:03 am

    Given the availability of for-each style loops, it seems to me that iteration has changed since those earlier studies. In fact, those loops throw another complexity into the teaching of plain iteration that didn’t exist in C or Pascal. If you go with iteration first, should it be the traditional for and while loops, or should you start with the for-each style, which is generally preferred in real programming because it is less error-prone? It is tempting to say the latter, but that has broader impacts because the for-each loop needs to iterate through something so students have to be introduced to some type of sequence before they can use it.

    In the “traditional” approach I believe that most people do iteration with loops first, and only after that has been mastered do they move on to sequences of values. However, the for-each loop, because it runs through a sequence of values, flips that around.

    Indeed, a challenge with iteration first is that most languages have 3-4 constructs for iteration: for, while, do-while, and some form of for-each loop. You can pick just one to focus on, but it provides an incomplete picture and might be showing a style that is considered bad for that language. Those choices and the complexity that comes with them don’t exist when you do basic iteration with recursion.

    Reply
    • 6. gasstationwithoutpumps  |  June 13, 2018 at 4:12 pm

      Python makes the “foreach” stye the default (to do numeric iteration requires creating a range). I think it is much easier to teach than the C-style for loop, since almost any sort of container can be the object iterated over (character in string, number in range, item in list, item in set, …). Iteration over the elements of some container is a more natural construct for more people than counting out the indices of an array, and is MUCH simpler than recursion.

      Reply
      • 7. Mark Lewis  |  June 14, 2018 at 12:25 pm

        This leads to the question, do you teach containers before the for loop, or do you introduce a counting for-loop using the Python range syntax without revealing to them that it has more power than that until later?

        I teach CS1 with Scala where the foreach style loop is the only for loop and higher-order methods like map and filter are standard style. As a result, I cover sequences before I cover loops. I don’t have to because I can write a counting loop with for(i <- 1 to 10), but given the power of the collections library, I don't feel a need to rush to general iteration. In Python, you could do something similar by using list comprehensions for a while before going to for loops.

        Reply
        • 8. gasstationwithoutpumps  |  June 14, 2018 at 2:58 pm

          I don’t teach beginning programming to undergrads, so I don’t have a tested answer, but I would teach iteration over containers before I would do counting loops, especially since letters in a string are a natural example.

          With grad students who were just starting programming, the first loop they saw was “for line in sys.stdin:”

          Reply
  • […] one is trying to teach both. For me, this is a well-supported statement of theory. I have written about the work by Anderson and Wiedenbeck supporting this argument. I have also written about the terrific work by Pirolli exploring […]

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trackback this post  |  Subscribe to the comments via RSS Feed


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 5,317 other followers

Feeds

Recent Posts

Blog Stats

  • 1,554,211 hits
March 2018
M T W T F S S
« Feb   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

CS Teaching Tips


%d bloggers like this: