Docsity

Quiz 18 in CSCE 330 Fall 2007 - Recursive Function Error Identification, Quizzes of Computer Science

Toggle sidebar
bg1
CSCE 330 Fall 2007
Quiz 18
Assigned Tuesday 07-12-04
A recursive function has two parts, the basis and the inductive step.
1. The basis computes the result for sufficiently small arguments, without
making any recursive call.
2. The inductive step calls the function recursively, with smaller arguments.
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)
1

Partial preview of the text

Download Quiz 18 in CSCE 330 Fall 2007 - Recursive Function Error Identification and more Quizzes Computer Science in PDF only on Docsity!

CSCE 330 Fall 2007

Quiz 18

Assigned Tuesday 07-12-

A recursive function has two parts, the basis and the inductive step.

  1. The basis computes the result for sufficiently small arguments, without making any recursive call.
  2. The inductive step calls the function recursively, with smaller arguments.

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)