
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The solution to quiz 18 in the csce 330 fall 2007 course, where students were asked to identify the error in a recursive function intended to reverse a list. The function in question breaks one of the two rules of recursion: the inductive step. Instead of making a recursive call with smaller arguments, it calls the function with the same size argument, leading to an infinite recursion.
Typology: Quizzes
1 / 1
This page cannot be seen from the preview
Don't miss anything!

A recursive function has two parts, the basis and the inductive step.
The following recursive function (which is intended to reverse a list and which is almost identical to the correct version of naive reverse that we discussed in class on Thursday) breaks one of these two rules. Which one? In which way?
fun reverse(L) = if L = nil then nil else reverse(L) @ [hd(L)];
Answer: The second (because the recursive call does not have a smaller argument)