EROSI - Visualising Recursion and Discovering New Errors Carlisle E. George School of Computing Science Middlesex University, The Burroughs London NW4 4BT, United Kingdom
[email protected] Abstract This paper introduces a novel software visualisation aid, the EROSI (Explicit Representer Of Subprogram Invocations) tutor, hypothesised to support the acquisition (by novice programmers) of a mental model to facilitate the comprehension and use of recursion as a problem solving technique. Novices found the EROSI tutor easy to use, interesting and a valuable visualisation aid to forming correct mental models of recursive processes. Studies concluded that although novices many have a correct mental model of recursion, various errors and misconceptions (identified) due to exogenous factors affect their ability to complete recursive tasks.
'1 Introduction Over the past decade numerous researchers have identified that students have special problems learning and understanding recursion and in applying recursive principles to problem solving [1,5,7,8,9,11,13]. A good understanding of recursion is an essential asset for computer science students. It is a powerful problem-solving technique in programming [3] and helps to better understand and manipulate complex data structures [12]. A recursive algorithm may be defined as a process capable of calling new instantiations of itself with control passing forward to successive instantiations (active flow of control) and back from terminated ones (passive flow of control). Kahney [7] refers to this conceptual notion as the copies model of rectmsion. Flow of control in recursion may be active, referring to the fact that the programmer explicitly directs the algorithm to call itself or passive, when control is automatically passed back to the previously suspended processes. This paper is primarily concerned with linear recursive algorithms [121 (within the context of Pascal programming). They have only one recursive call and may be fitrther classified as exhibiting tail recursion or embedded recursion, according to the position of the recursive call within the algorithm. In tail recursion, the recursive call is the last action of the algorithm. Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advant -age and that copies bear this notice and the full citation on the first page. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. SIGCSE 2000 3/00 Austin, TX, USA © 2000 ACM 1 - 5 8 1 1 3 - 2 1 3 - 1 / 0 0 / 0 0 0 3 . _ $ 5 . 0 0
In tail recursive functions a recursive call is made on a reduced input parameter and after the last instantiation (base case) has finished executing, partial solutions must be combined to form a total solution. In embedded recursion, the recursive call is embedded into a group of algorithm statements, hence, there are other actions to be performed after the recursive call. Previous research [7,8] have concluded that novices easily understand tail recursion using procedures but have difficulty with understanding tail recursion with functions and embedded recursion. This is because students have difficulty understanding the control mechanism of recursion (especially passive flow of control) and do not have proper mental models of r~ursive processes. George [4] argues that a major problem of understanding reecursion is subsumed into the problem of having an effective mental model of subprogram invocations. Many novices seem to naturally develop a static-text subprogram execution model where the subprogram is seen as a static segment of program code above the main body which is executed. George[4] argues for aiding novices in visualising a more sophisticated subprogram execution model (which he calls the dynamic-logical model) which places emphasis on various dynamic processes logically representing a subprogram execution. In the dynamic-logical model each subprogram call or invocation (effectively) involves suspending the calling program; transferring execution control and sometimes data to a new and unique manifestation or copy of the subprogram called (i.e. active flow of control); then transferring control and sometimes data back to the calling program after the subprogram execution has ended (i.e. passive control flow). The essential feature of the dynamiclogical model is that each subprogram copy is visualised as (physically) separate from the original subprogram text, having its own data set (variable values, parameter values). Linearly extending the dynamic-logical subprogram execution model to self-referential calls results in the copies model of recursion which experts possess [7]. In effect, the dynamic-logical model serves as an 'advance organiser' [21 for the copies model by providing the necessary 'anchoring ideas' needed for understanding this more cognitively complex concept. The dynamic-logical model therefore provides prerequisite concepts (familiar existing knowledge) for the copies model, which in turn provides an understanding of the process of recursion. 305
2 The EROSI Tutor The EROSI (Explicit Representer Of Subprogram Invocations) tutor uses visualisation and animation as well as sound and colour to simulate the dynamic-logical model of subprogram calls, which is linearly and progressively extended to the copies model of recursion. It may be classified as a Program Visualisation System [10]. The tutor facilitates dynamic code visualisation (showing what parts of the code are being executed as the program is run by simultaneously highlighting them) and dynamic algorithm visualisation (generating an animation of an algorithm in action). Figure 1 gives an overview of the EROSI system architecture. system
SimulationModules
•y~t~m
I I I I I I I I
I Graphic& L UtilitiesUni~ ~~ ,
,L V :.: [~::'~.:.:~::.:::::':~
the 'copy' of the subprogram back to the previously suspended calling program. (d) Flow of data, clearly defined within the context of its role in solving subproblems, i.e. each data object (e.g. variables) traced through the series of transformations in which it participates. (e) Resulting actions (output) of a program/subprogram. (1) Unique and separate invocations of subprograms. On logging on to the EROSI tutor a learner is presented with a menu which allows him/her to either find information about the system, change system settings, choose various types of simulations or quit the system. Figure 2 shows the main menu interface of the tutor.
......
f V i s u . l Output "~ a. pro8.execution ~ l 'b. prog.ou~ut J
:~:~i:~:!:~:~:!:~::':~:~;~:'~:~:~:!:!:~:~:~:' ::~:;::::'::':~ ~-:::' ::~:':~:~:~:-::~:~:~:' ::':~:~ -':~:.;:-:::.;:.;~&:::':~:~:~:~:~:!&:::' :::~:!~:~ I~fi ~,--,,, • ~:¢~,
~'~ ~
......
~~~~!!~~~.:.:!i::'.~:' :~::'.'::~:~*' [!~l~'~'~:::::::~::~::::::~:' . :'.:'.::.. . . . . . . . . ~(~-#;
E~.'.':I.,'.~
~
".
!!!-:~:::::::::::: ~:i:.:~...... !~!~ii:'.:i
:::::::-:~::::::~::~:..::>&~::::::::
N g,.,~,~,t.'~:~' .J .&~N........ Figure 8 - Final execution history: embedded recursion
4 Using The EROSI Tutor
Figure 6 - Interface for start of embedded recursive example
Figure 6 shows the start of the simulation. The user must input an integer value in the range of zero to two. After the user has input his preferred value, the execution process beings. Figure 7 shows a snapshot of the execution in progress.
This section briefly discusses some results from two studies (Pilot Study and Final Study) of students on introductory BSc programming courses who used the EROSI Tutor in laboratory sessions (the treatment). See George[4] for experimental details. All students were classified as novices since they had little or no previous working knowledge of Pascal (before the introductory course) nor did they have experience with evaluating recursive programs or using recursion in programming. In the Pilot study, during pretreatment tasks, students naturally used a static-text model of subprogram executions (i.e. the sequential tracing of program control through the textual representation of the program's code). Post-treatment scores and diagrammatic illustrations showed that generally students were better able to evaluate recursive programs (involving embedded recursion and tail recursive functions) by applying a copies 308
model to simulate the recursive processes. Pre-treatment minus post-treatment mean difference on achievement in recursion were very significant for both measured abilities namely 'read and understand recursive programs', (t = 5.12, p < 0.005) and 'write recursive programs' (t = 5.09, p < 0.005). The studies also concluded that the EROSI tutor was easy to use and generally perceived as interesting and helpful. Also, the conceptual representations of the dynamic-logical (copies) subprogram model for recursion were clear and easily understood by most students. 5 Novice Errors and Misconceptions A Final study provided valuable insight into errors made by novices when attempting to evaluate and construct recursive algorithms, after the instructional treatment. Also various observations and findings gave further insight into the difficulties associated with the teaching and learning of recursion. It was observed that many of the (post-treatment) incorrect responses given when evaluating recursive algorithms did not generally arise from an inadequate model of recursion or from a poor understanding of the copies execution model of recursion. With the aid of diagrammatic traces, many students demonstrated a good understanding of the copies model, (i.e. the notions of unique subprogram invocations and flow of control) but gave incorrect responses due to several exogenous factors. These especially included: misconceptions concerning variable updating and computer memory storage; difficulty with evaluating conditional statements; and idiosyncratic notions about the behaviour of some program elements. Misconceptions concerning variable updating were generally related to the use of an 'immediate invocation update' evaluation strategy or a 'delayed invocation update' strategy. The former concerned the misconception that the value of a variable was explicitly changed by an argument expression. The latter concerned the misconception that on return of control to a suspended process, the value of a variable was changed to correspond to the parameter value in a previous invocation. Misconceptions about memory storage concerned the attempt to understand aspects of the recursive execution process (e.g. variable storage) in terms of the technical workings of computers. Difficulty with conditional statements stemmed from an inability to rationalise certain expressions, such as 'IF 11' which was false and then proceeded to think that '1