Recursion vs. iteration: An empirical study of comprehension

Recursion vs. iteration: An empirical study of comprehension

Recursion vs. Iteration: An Empirical Study of Comprehension Alan C. Benander, CIeueland Barbara A. Benander, State University, Cleveland, An exte...

926KB Sizes 7 Downloads 93 Views

Recursion vs. Iteration: An Empirical Study of Comprehension

Alan C. Benander, CIeueland

Barbara A. Benander,

State University, Cleveland,

An extensive study involving three test groups over a period of three different years was performed to determine differences between comprehension of recursive and iterative code constructs. This study involved computer

science

structure responses, x2

students

classes which

enrolled

using were

in six different

PASCAL

and

statistically

test, one task-searching

obtained

analyzed.

a linked

data 275

Using

a

list for a given

value-showed a statistically significant fp = 0.006) difference in comprehension favoring recursion. Another taskmaking a copy of a linked list -favored iteration, responses of means

but not with

statistical

significance.

with correct comprehension, test was performed on the

Among

a comparison comprehension

times among the latter two groups in the study. There was a faster rate of comprehension of the recursive code for both of the tasks (p = 0.096 for the search and p = 0.045 for the copy). A two-way analysis of variance

suggested

effect between hension time.

1.

a tendency

task and construct

and Howard

Pu

Ohio

toward

an interaction

in terms

of compre-

INTRODUCTION

Most of the research on recursive programming has been in the area of pedagog (Anderson et al., 1984; Piroli and Anderson, 1985; Wiedenbeck, 1989) and complexity analysis (Burton and Campbell, 1986; Hunt and Rosenkrantz, 1986). The literature contains several approaches that educators can USC to teach recursion (Ford, 1984; Kruse, 1982). The Towers of Hanoi puzzle, the classic example used by educators as an example of an iteratively difficult, recursively easy problem, has been studied exten-

Address correspondence to Dr. Barbara A. Benander, Computer und Injiirmucivn Science, Cleveland State University, 2121 Euclid Avenue, Cleveland, OH 44115.

J. SYSTEMS SOFIWARE 1996; 32:73-82 0 1996 by Elsevier Science Inc. 655 Avenue of the Americas, New York, NY 10010

sively (Birtwistle, 1985; Mayer and Perkins, 1984; Maziar, 1985; Meyer, 1984; Rohl, 1987; Stadel, 1984) and is found in practically every data structures textbook. Complexity analysis of recursive routines has been an important area of research because of the overhead involved with recursion in terms of memory and computing time requirements. Little, if any, research, however, has been done on recursive code comprehension. Code comprehension plays a role in almost all software tasks, including maintenance, debugging, and code reviews. Its vital role in maintenance is obvious, and with estimates of software maintenance at 60-80% (McLeod, 1994) of the total software budget for many organizations, the study of code comprehension becomes more important. Indeed, there has been an increase in research devoted to comprehension, but not to recursive code comprehension, per SC. Research on code comprehension includes theories uf comprehension that explore the intrinsic nature of the task of comprehension (Brooks, 1983; Crosby and Stelovsky, 1990; Wiedenbeck, 1991) as well as experimental studies that investigate the effect of program style characteristics, such as indentation (Miara et al. 1983) and delimiters (Sykes et al. 1983), on comprehension. Others have conducted experiments attempting to understand the mental representation of a program that is formed during program comprehension (Wiedenbeck and Fix, 1993). Soloway et al. (1988) investigated the knowledge and processing strategies that programmers use in code comprehension. Today almost all computer science educators and professionals would agree with McCracken’s (1987) contention that recursion is fundamental to computer programming. Certainly, the concept of recursion is essential to tree searching and traversal,

0164-1212/96/$15.00 SSDI 0164-1212(95)00043-Z

74

A. C. Benander et al.

J. SYSTEMSSOFIWARE 1996: 32~73-82

which in turn are important in areas such as graph theory, artificial intelligence, neural networks, logical programming, and recursive database querying. Yet, many educators express apprehension about trying to teach recursion to novice programmers because it is difficult to trace recursive code and perhaps even more difficult to verify its reliability. This is true even if the student is somewhat comfortable with proofs by mathematical induction. Novice programmers also have problems learning recursion because, as Sinha and Vessey (1992) point out, they have few real-world analogies on which they can formulate a mental model, in contrast with iteration. Because of these problems with teaching and learning recursio, many educators also believe that recursion is much more difficult to comprehend than iteration. The purpose of our experiment was to provide empirical evidence to support or refute this contention. Obviously, the effect of recursion on code comprehension plays a role in a programmer’s choice of iterative or recursive construct only if the programmer perceives no significant advantage, from a programming time standpoint, to use of either construct. For example, in the case of the Towers of Hanoi problem, a programmer would almost certainly choose the recursive construct, since this would, most likely require much less programming time. Indeed, how a programmer chooses a certain construct is a critical question in itself. This question, as it relates to recursion and iteration, was explored in the empirical study done by Sinha and Vessey (1992). In their article, one of the hypotheses tested is that a programmer’s choice of recursion or iteration is a matter of matching the task with the construct. For example, computation of factorials appears to be an inherently recursive task. Furthermore, if the problem is also defined recursively, that is, the problem representation is recursive, then the choice would be further biased toward recursion. It would seem that using the construct with better cognitive fit (matching task with construct and matching problem representation with construct) would lead to higher programmer proficiency and thus should be the preferable choice. Sinha and Vessey related choice of construct (iterative or recursive) to cognitive fit, and cited Horowitz and Sahni (1990) and Winston and Horn (1981) as suggesting that the type of problem and the way ti is represented would determine the most advantageous construct (i.e., an iterative or recursive construct) to use. Among LISP programmers, Sinha and Vessey did find some correlation between programming perfor-

mance and choice of construct. However, among PASCAL programmers in their study, none of the following propositions were supported: 1) performance will be enhanced by matching task, problem representation, and construct; 2) performance will be enhanced by matching problem representation to task; and 3) performance will be enhanced by matching construct to task. By performance, they meant the time needed to successfully complete each problem. If a programmer were aware that the choice of construct might have little effect on coding time (as the Sinha and Vessey study suggests for PASCAL programmers), the programmer would consider more closely other criteria (such as comprehension) for choosing construct. 2. METHODOLOGY The subjects for this empirical study were computer science majors taking a data structures course using PASCAL. Three groups of students were involved from three different years in which the course was taught. Each group consisted of two different sections of students taking the same lo-week course. All of the students followed the same syllabus and used the same textbook. Two instructors (two of the authors) taught all of the subjects and used the same lecture notes. During the last week of class, each student was given a small piece of PASCAL code to comprehend. The code involved performing a task on a linked list. One section in the group received the iterative version, and the other section received the recursive version of the same task. The students were told to write a single sentence describing the purpose of the code. The responses were graded by the instructors and marked as being either correct or incorrect. On the next class day, before returning the results (but not the code itself), another short PASCAL program segment to perform another task was given to each student in each section in the group, again for the purpose of testing comprehension. The section that had previously received an iterative version was given a recursive version, and vice versa. In Groups II and III, the time needed by each student to complete the task of comprehension was also recorded. All of the students in the study were familiar with functions and procedures in PASCAL. They had all studied linked lists for most of the quarter and had written programs involving linked lists. All students had used iterative and recursive constructs (dealing with binary trees) in various programming assignments.

Recursion vs. Iteration

J. SYSTEMS SOFTWARE 1996; 32~73-82

The instructors involved in the experiment had defined a (singly) linked list as a list of records, each record having data field(s) and a pointer field used to logically link the records in the list. Iterative code constructs to perform standard operations on linked lists were presented to the students in lectures and in the textbook. Students also were given lectures on doubly and multiply linked lists. A recursive definition of a linked list was not presented. Students were given lectures on recursion with specific examples involving binary tree traversal. For the Group I experiment, students had as long as they needed to give their responses. Comprehension times were not recorded. In subsequent years, students in Groups II and III were also given as much time as they needed, but also had their comprehension times recorded (to the nearest minute). Students in these groups were aware that their times were being recorded by the instructor and were allowed to work on other class assignments as soon as they had finished. The two tasks that students were asked to comprehend were searching a linked list of integers for a specified value and making a copy of a linked list. The search was implemented (iteratively and recursively) as a function in PASCAL, and the copy was implemented as a procedure (see Appendix A and Bl. The instructions given to the students were: “Assume nodepter is a Pascal pointer type used to define a linked list with records having a data field called item and a pointer field called next. Using only one sentence, what does the following procedure (function) do?” The linked list was chosen as the data structure for the study because the subjects in this experiment were all familiar with this data structure, having studied it and written programs with linked lists for about 9 weeks; the linked list lends itself to recursive and iterative representations (thus minimizing a cognitive fit bias); and the linked list is a ubiquitous data structure, lending more import to the results obtained from the experiment. The methodology of this experiment either eliminates or greatly minimizes four sources of variation in code comprehension as explained by a theory of comprehension proposed by Brooks (1983):

Both consisted of a very few lines of code and were written in the same programming style with respect to indentation and placement of begin-end delimiters. Neither had any documentation, and the name of each function and procedure was purposely chosen so as to give no clue as to its purpose. Other research (Wiedenbeck, 1991) indicates that a meaningful name for a module becomes an important beacon for comprehension. The task being performed by the programmer (e.g., modification, debugging, code testing). In this ex-

periment, students in different sections performed the same task, that is, simply to describe in one sentence what the code was doing. The individual differences. In this experiment, all of the students were at the same level in the computer science program; all had used the same syllabus, the same textbook, and all had been taught by one of two instructors, who used the same lecture notes. Thus, the programming and instructional backgrounds of the students were nearly identical.

Using the responses from the three groups, x2 tests were performed using SAS. Each response was labeled correct or incorrect by the instructor grading the responses. For each of the two tasks and for each group, the null hypothesis used for the tests was “There is no difference in comprehension between the recursive and the iterative versions.” For the Group II and Group III studies, a comparison of means analysis was done on the recorded timings for those responses labeled correct. Only the correct responses were used since response times for incorrect answers could not be used in a measure of comprehension time. Using the t test procedure of SAS, the recorded times on the correct responses were analyzed, using the null hypothesis “There is no difference in means of times needed to comprehend the recursive code and the iterative code.” A two-way analysis of variance (ANOVA) was also run, with construct (iterative or recursive) and task (search or copy) as the independent variables and comprehension time as the dependent variable.

The task performed by the program. In this experi-

3. RESULTS: COMPARING

ment, both the recursive performed the same task.

INCORRECT

and iterative

versions

The intrinsic properties of rhe program text, such as language, length, and documentation. In this exper-

iment, both the recursive and iterative versions were written in the same language (PASCAL).

75

CORRECT WITH COMPREHENSION RESPONSES

A total of 275 responses (87 from Group I, 94 from Group II, and 94 from Group III) were obtained from the three groups over the 3-year period of the study (an odd number was obtained due to slight variance in student attendance over the 2-day period

76

A. C. Benander et al.

J. SYSTEMS SOFTWARE 1996; 3273-82

Table 1. Group I Results Iterative Correct

Recursive

Incorrect

Total

Correct

Incorrect

Total

A. Comprehension of the search function* Frequency 9.0 Expected 10.2 Percentage 22.0 Row percent 40.9 Column percent 47.4

13.0 11.8 31.7 59.1 59.1

22

10.0 8.8 24.4 52.6 52.6

9.0 10.2 22.0 47.4 40.9

19

B. Comprehension of the copy procedure* Frequency 5.0 Expected 8.0 Percentage 10.9 Row percentage 21.7 Column percentage 31.3

18.0 15.0 39.1 78.3 60.0

23

11.0 8.0 23.9 47.8 68.8

12.0 15.0 26.1 52.2 40.0

23

x2 value *0.563, ‘3.450; probability *0.453, ‘0.063.

in each year for conducting the experiment). Each student filled out a response for a task involving recursion on one day of the experiment and a response for a different task involving iteration on another day of the experiment. The tasks involved searching a linked list for a value and making a copy of a linked list. Tables l-4 summarize the results of the x2 tests. Using a x2 test, “expected” results are based on the hypothesis that there is no difference in performance between the groups being measured (in our case, iterative and recursive groups). For example, in Table lA, among 41 total responses, 19 were correct and 22 incorrect. The ratio of correct to total responses, 19/41, is the expected ratio for both groups. Thus, the expected number of correct responses for the iterative group is 19/41* 22 (total responses for the iterative group), which equals 10.2. Similarly, the expected number of correct responses for the recursive group is 19/41* 19 (total responses for the recursive group), which equals 8.8.

With regard to the search function, in each of the three groups, the recursive version of the search function had more observed correct responses than expected. Concomitantly, the iterative version of the search function had more observed incorrect responses in each group than expected. The results were statistically significant for Group II (p = 0.004). For the search function, the aggregate results (136 responses) of the three groups tested (Table 4) show a statistically significantly (p = 0.006) better performance in comprehending the recursive version of the search function compared with the iterative version. Among the 70 responses obtained for the recursive version of the search function, 44 were correct while 26 were incorrect, for a 62.9% correct total. In contrast, among the 66 responses obtained for the iterative version, only 26 were correct and 40 incorrect, for a 39.4% correct total. Figure 1 illustrates these results. Observed results of the copy procedure task were less uniform. Group II and Group III responses

Table 2. Group II Results Iterative

Recursive

Incorrect

Total

Correct

Incorrect

Total

A. Comprehension of the search function* Frequency 8.0 Expected 13.0 Percentage 16.7 Row percentage 32.0 Column percentage 32.0

17.0 12.0 35.4 68.0 73.9

25

17.0 12.0

6.0 11.0

23

B. Comprehension of the copy procedure’ Frequency 12.0 Expected 8.5 Percentage 26.1 Row percentage 52.2 Column percentage 70.6

11.0 14.5 23.9 47.8 37.9

23

Correct

x2 value *8.432, ‘4.572; probability *O.M)4, $0.032.

35.4

12.5

73.9 68.0

26.1 26.1

5.0 8.5 10.9 21.7 29.4

18.0 14.5 39.1 78.3 62.1

23

Recursion vs. Iteration

77

J. SYSTEMS SOFIWARE 1996; 32:73-82

Table 3. Group III Results Iterative Correct

Recursive

Incorrect

Total

Correct

Incorrect

Total

A. Comprehension of the search function* Frequency 9.0 Expected 10.5 Percentage 19.2 Row percentage 47.4 Column percentage 34.6

10.0 8.5 21.3 52.6 47.6

19

17.0 15.5 36.2 60.7 65.4

11.0 12.5 23.4 39.3 52.4

28

B. Comprehension of the Copy Procedure* Frequency 21.0 Expected 18.5 Percentage 44.7 Row percentage 75.0 Column percentage 67.7

7.0 9.5 14.9 25.0 43.8

28

10.0 12.5 21.3 52.6 32.3

9.0 6.5 19.2 47.4 56.3

19

,y* value *0.816, *2.522; probability *0.366, ‘0.112

(Table 2 and 3) showed higher than expected correct responses for the iterative version, with Group II results being statistically significant (p = 0.032). Group I, on the other hand, showed higher than expected correct responses for the recursive version. The aggregate totals (139 responses) for the copy procedure for the three groups tested (Table 4) had a higher number of correct responses than expected for the iterative version. There were 51.4% (38/74) correct responses for the iterative version compared with 40.0% (26/65) for the recursive version. Figure 2 illustrates these results. 4. RESULTS: COMPARING COMPREHENSION TIMES OF CORRECT RESPONSES Timings for comprehension were recorded for subject responses from Groups II and III of the experiment. Using only the correct responses, mean comprehension times for the iterative and recursive versions for each task were used in a comparison

of means test using the t test procedure of SAS. Table 5 contains the results. Our null hypothesis, “There is no difference in mean times for correct comprehension between the iterative and recursive versions,” was rejected with statistical significance in the Group II case for the search function (p = 0.036) and with statistical significance in the Group III case for the copy procedure (p = 0.033). In both of these cases, mean comprehension times for the recursive version were less than for the iterative version. In fact, as can be seen from Table 5, the mean comprehension time for the recursive version in each case was less than the mean comprehension time for the iterative version. The aggregate results (Table 6) show that the mean time for correctly comprehending the recursive search function was 3.78 minutes. In comparison, the mean time for the iterative version was 4.65 minutes. The difference in mean comprehension times between the aggregate correct responses for the two

Table 4. Aggregate Results Iterative Correct

Recursive

Incorrect

Total

Correct

Incorrect

Total

A. Comprehension of the search function* Frequency 26.0 34.0 Expected Percentage 19.1 39.4 Row percentage Column percentage 37.1

40.0 32.0 29.4 60.6 60.6

66

44.0 36.0 32.4 62.9 62.9

26.0 34.0 19.1 37.1 39.4

70

B. Comprehension of the copy procedure’ Frequency 38.0 34.1 Expected Percentage 27.3 Row percentage 51.4 Column percentage 59.4

36.0 39.9 25.9 48.7 48.0

74

26.0 29.9 18.7 40.0 40.6

39.0 35.1 28.1 60.0 52.0

65

x2 value *7.487, *1.795; probability *0.006, *O.lBO.

A. C. Benander et al.

J. SYSTEMS SOFTWARE 1996: 32~13-82

78

Correot

Incorreat

(40)

Incorrect

(26)

Total = 70

(26)

Total =66

Correct

(44)

Correct

(26)

Recursive Comprehension

Iterative Comprehension Figure 1. Search Function.

Total = 74 Incorrect

(36) Correct

(38)

Incorrect

(39)

Total =65

Recursive Comprehension

Iterative Comprehension Figure 2. Copy Procedure.

Table 5. Comparison

of Mean Comprehension

Times among Correct Responses Copy Procedure

Search Function construct A. Group II Iterative Recursive

Mean

SD

5.75 4.13

1.91 1.51

P

Mean

SD

5.18 4.00

2.48 1.00

0.036 B. Group III Iterative Recursive

3.67 3.47

1.94 1.28

0.329 3.24 2.00

1.61 0.94

0.759 SD, standard

0.033

deviation.

Table 6. Aggregate Comparison

of Mean Comprehension

Times among Correct Responses

Search Function (n = 49) Construct

Mean

SD

Iterative Recursive

4.65 3.78

2.15 1.41

Copy Procedure (n = 47) P

0.96 SD, standard

P

deviation.

Mean

SD

3.91 2.67

2.13 1.34

P

0.045

Recursion vs. Iteration

79

J. SYSTEMS SOFTWARE 1996;32~73-82

Mean comprehension

Iterative Figure 3.

time (minutes)

Mean comprehension time (minutes)

Iterative

Recursive

Search Function.

versions of the copy procedure was even greater than for the search function. Table 6 shows the recursive version of the copy procedure with mean time of 2.67 minutes and the iterative version with mean time of 3.91 minutes. The null hypothesis of equal means was rejected (p = 0.045). The results for the copy procedure are particularly interesting in light of the results reported in Section 3 for Group II and Group III responses. These two groups performed better (in terms of correctly comprehending the code) on the iterative version of the copy procedure. Yet, those students who correctly comprehended the recursive version did so in significantly less time than those who correctly comprehended the iterative version. Figures 3 and 4 illustrate the aggregate results of the comparison of means test. The two-way ANOVA, which was run in SAS, used construct (iterative and recursive) and task (copy and search) as independent variables. The comprehension time was used as the dependent variable. As with the t test, only the comprehension times that corresponded to correctly comprehended tasks were used. The design in such an ANOVA permits testing for the influence of one factor in the presence of another factor. Mean comprehension times for the recursive and iterative constructs were 3.43 and 4.17 minutes, respectively. Mean times for copy and search tasks were 3.51 and 4.08 minutes, respectively. Table 6 gives mean times for each of the four different construct-task groups. The two-way ANOVA results showed significant differences in comprehension times among these four groups (p =

Figure 4.

Reoursive

Copy Procedure.

0.026). Between the two different constructs, the difference in comprehension times was significant (p = 0.049), with the recursive constructs being comprehended in less time than the iterative constructs. Considering the two tasks, the mean time for correctly comprehending the copy tasks was less than the mean time for the search, but the difference was not statistically significant. In trying to determine interaction effect between construct and task, construct * task was used as the source in the ANOVA test and produced p = 0.071, suggesting a tendency toward an interaction effect between the construct and task. Table 7 summarizes results of the ANOVA.

5. REMARKS

AND CONCLUSIONS

Code comprehension is a very critical task in software development. Those involved with code maintenance would not dispute this. Programmers writing first-time modules are also involved in reading their own code, and in reading others’ code in order to gain insights into their own construction. The debug-

Table 7. Two-Way ANOVA Source Model Construct Task Construct Independent comprehension

* task

F Value

Pr > F

3.24 3.99 2.39 3.34

0.026 0.049 0.126 0.071

variables: construct and task; dependent time; number of observations: 96.

variable:

80

J. SYSTEMSSOFTWARE

A. C. Benander et al.

1996; 32173-82

ging effort has been shown empirically (Benander et al., 1989) to be affected by many factors, and comprehension is certainly an overriding one. This empirical study focused on recursive code comprehension compared with iterative code comprehension for concise code segments. One of the limitations of this study is the use of student subjects. Hence, one should be careful in generalizing the results of this experiment to professional programmers. However, in the case of code comprehension, as opposed to other software tasks (e.g., systems analysis and program construction), empirical results using student subjects may be more extendable to professional programmers. The reason for this is that the task of concise code comprehension involves just that-concise code-regardless of whether or not the code segment is found in a large, industrial program or a smaller student program. At the same time, it should be recognized that students will probably not be as proficient at comprehending concise code as professionals. Also, comprehension may be affected by factors other than type of construct used. In this experiment, an attempt was made to minimize these factors by using the same task (e.g., copy or search) in comparing an iterative construct with a recursive construct. Also, both code segments were very small, the programming style was the same, and procedure and function name tokens were eliminated in both. In addition, the same basic data structure, a linked list, was used in each of the experimental code segments. However, even though the students were not presented with a recursive definition of a linked list, it is easily represented recursively, and this may present a possible limitation of the study in terms of the neutrality of the data structure. This study was done with three separate groups in order to obtain a sample size that would allow us to attach some significance to the results. The number of responses (275 for the correct/incorrect comparison and 96 for the time study comparison) allow for some meaningful interpretations even with the caveats mentioned above. At the least, this study gives empirical evidence suggesting that, for small, simple tasks involving linked lists, code comprehension is most likely not

impaired by coding recursively rather than iteratively. Our experiment yielded statistically significantly better performance (in terms of correctly comprehending the code) for comprehension of the recursive search function compared with the iterative version. Also, in comparing comprehension times among those subjects who had correctly comprehended the code, both tasks were performed faster on the recursive versions (p = 0.045 for the copy task and p = 0.096 for the search task). These results are even more significant when viewed in light of a favorable bias that novice programmers have for iteration (Sinha and Vessey, 19921, as well as their greater programming experience with it. The results of this empirical study suggest some pedagogical approaches that educators should consider. In particular, this study suggests that computer science educators should not avoid presenting their students with examples of recursive code, presuming that their students may have difficulty comprehending it. Rohl (1984) has written an excellent book which could be used for PASCAL programmers, and which could easily be adapted to programmers of other languages, such as C. Guidelines for teaching recursion that can be easily used in the classroom can be found in the literature (Ford, 1984; Kruse, 1982). For researchers, more empirical evidence is needed in the area of recursive and iterative code comprehension. In particular, what tokens led the subjects to faster comprehension of the recursive code for both tasks in both groups of the time study? What tokens led to a larger number of subjects comprehending the iterative version of the copy task, but a larger number of subjects comprehending the recursive version of the search task? Perhaps the search task is more naturally recursive than the copy task; searching continues on the basis of what occurred in the previous step, whereas copying continues independently of what occurred in the previous step. In any case, additional research needs to be done on the nature of recursive and iterative tasks. Also, would similar results be obtained for larger and more complex programming segments? Answers to these questions would clearly benefit both educators and professional programmers.

Recursion

vs. Iteration

J. SYSTEMS SOFTWARE 1996: 32:73-82

81

Appendix A. I. Recursive Version of Search

II. Iterative Version of Search

I. function Boo (head : nodeptr; k : integer) : boolean;

II. function Boo (head: nodeptr; k: integer) : boolean;

begin if head = nil then

type statetype = tx, y, z); var state : statetype;

Boo := false else if k = head^.item then Boo := true else Boo := Boo (head*.next,k) end;

begin state := x; repeat if head = nil then state := y else if k = head-item then state := z else head := head^.next until state <> x; Boo := state = z end;

Appendix B. I. Recursive Version of Copy

II. Iterative Version of Copy

I.

procedure Testproc (var head1 : nodeptr; head2 : nodeptr); begin if head2 = nil then head1 := nil else begin new(head 1); headl^.item := head2^.item; Testprocrec (headl^.next, end

head2^.next)

end;

II. procedure Testproc (var head1 : nodeptr; head 2 : nodeptr); var p : nodeptr; begin if head2 = nil then head1 := nil else begin new (headl); headl^.item := head2^.item; head2 := head2^.next; p := headl; while head2 <> nil do begin new (p^.next); p*.next^.item := head2^.item; p := p^.next; head2 := head2^.next end; p*.next := nil end end;

REFERENCES Anderson, J. R., Farrell, R., and Sauers, R., Learning to Program in LISP, Cogn. Sci. 8, 87-129 (1984). Benander, A. C., Benander, B. A., and Gorla, N., An Empirical Study of COBOL Programs Via a Style Analyzer: The Benefits of Good Programming Style, J. Cyst. Soflware 10, 271-279 (1989). Birtwistle, G., The Coroutines of Hanoi, SIGPLAN Not. 20(l), 9-10 (1985). Brooks, R., Towards a Theory of Comprehension of Computer Programs, Int. J. Man-Machine Stud. 18, 543-554 (1983).

R. P., and Campbell D. M., A Curious Recursive Function, ht. J. Comp. Math. 19, 245-257 (1986). Crosby, M., and Stelovsky, J., How Do We Read Algorithms? A Case Study, Computer 23, 24-35 (1990). Ford, G., An Implementation-Independent Approach to Teaching Recursion, Commun. ACM 213-216 (1984).

Burton,

Horowitz, E., and Sahni, S., Data Structures in Pascal, Computer Science Press, New York, 1990, p. 21.

Hunt, H. B., and Rosenkrantz, D. J., Recursion Schemes and Recursive Programs are Exponentially Hard to Analyze, Siam J. Comp. 15, 831-850 (1986).

82

A. C. Benander et al.

J. SYSTEMS SOFI’WARE 1996; 32:73-82

Kruse, R. L., On Teaching Recursion, Commun. ACM 92-95 (1982). Mayer, H., and Perkins, D., Towers of Hanoi Revisited: A Nonrecursive Surprise, SIGPLAN Not. 19(2), 80-84 (1984). Maziar, S., Solution of the Towers of Hanoi Problem Using a Binary Tree, SIGPLANNot. 20(5), 16-20 (1985). McCracken, D., Ruminations on Computer Science Curricula, Commun. ACM 30, 3-4 (1987). McLeod, R., Systems Analysis and Design, The Dryden Press, Orlando, Florida, 1994, p. 753. Meyer, B., A Note on Iterative Hanoi, SZGPLAN Not. 19(12), 38-40 (1984). Miara, R., Musselman, J., Navarro, J., and Shneiderman, B., Program Indentation and Comprehensibility, Commun. ACM 26, 861-867

(1983).

Piroli, P., and Anderson, J. R., The Role of Learning From Examples in the Acquisition of Recursive Programming Skills, Can. J. Psychol. 39, 240-272 (1985). Rohl, J. S., Recursion uia Pascal, Cambridge University Press, Cambridge, UK, 1984. Rohl, J. S., Towers of Hanoi: The Derivation of Some Iterative Versions, Comp. J. 30, 70-76 (1987).

Sinha, A., and Vessey, I., Cognitive Fit: An Empirical Study of Recursion and Iteration, IEEE Trans. Software Erg. 18, 368-379

(1992).

Soloway, E., Adelson, B., and Ehrlich, K., Knowledge and Processes in the Comprehension of Computer Programs, in The Nature of Expertise, (M. T. H. Chi, R. Glaser, and M. J. Farr, eds.), Lawrence Erlbaum, 1988. Stadel, M., Another Nonrecursive Algorithm for the Towers of Hanoi, SIGPLAN Not. 19(9), 34-36 (1984). Sykes, F., Tillman, R., and Shneiderman, B., The Effect of Scope Delimiters on Program Comprehension, Sofrware Pruct. Exp. 13, 817-824 (1983). Wiedenbeck, S., Learning Iteration and Recursion from Exampies, Int. J. Man-Machine Stud. 30, l-22 (1989). Wiedenbeck, S., The Initial Stage of Program Comprehension, int. J. Man-Machine Stud. 35, 517-540 (1991). Wiedenbeck, S., and Fix, V., Characteristics of the Mental Representations of Novice and Expert Programmers: An Empirical Study, Znt. J. Man-Machine Stud. 39, 793-812

(1993).

Winston, P. H., and Horn, B. K. P., LISP, Addison-Wesley, Reading, MA, 1981, p. 63.