View
219
Download
0
Embed Size (px)
Citation preview
IntroductionIntroduction
Goal: A visual representation of recursive
functionsUses: Pedagogical Debugging
Debugging StepsDebugging Steps
1. Recognize error2. Find the error in the code3. Determine how that spot relates to program
Debugger EvolutionDebugger Evolution
Command Line drivenText for the names and values of variablesKeyboard Input/Text OutputVarious breakpointsSingle Stepping
Graphic User Interface (GUI)Show the code executingReveal values of variables by clicking on themStill just names and values of variables
VisualizationVisualization
Sight provides the most understandingFor Effective Visualization (Stasko, et al., 93)
Include detailed text instructionsLink with instructional goalsPerform user testingInclude rewind/replay functions
RecursionRecursion
A recursive function is one that can call itselfBreaks large problems into small problemsBase casesTaught early in computer science courses
Taught at Westminster in CS 152, the second CS course
Factorial ExampleFactorial Example
n!=n*(n-1)*(n-2)*…*3*2*1In recursive form
n!=1 if n=1n!=n*(n-1)! if n>1
In Computer CodeFactorial(n){
If(n==1)Return 1;
elsereturn n*factorial(n-1); }
Factorial ExampleFactorial ExampleFactorial(4)
4*Factorial(3)
3*Factorial(2)
2*Factorial(1)
1
2*12
3*26
4*624
Typical problems using recursion
Typical problems using recursion
Missing, incorrect, or too exclusive base case Factorial can only work for nonnegative integers
Exorbitant and repetitive branching
The Recursive DebuggerThe Recursive Debugger
Goal-Visually depict recursive functionsUse of tree structure
Downward branchingOutward branching
Function BoxParameters, Return values, Received values
RecursionDebugger ClassRecursionDebugger Class
Software to create, update, and maintain display window
Evolved over 2 semestersCommand line basedGUI based
Requires tags to be inserted in user’s code
Factorial Before Tags added
Factorial Before Tags added
public class Fact{ public static void main(String args[]){ System.out.println(fact(Integer.parseInt(args[0])));} public static int fact(int n){ if (n==1){ return 1; } else{ int val=fact(n-1); return (n*val); }}}
Factorial with TagsFactorial with Tags public class Fact{ public static RecursionDebugger hp=new RecursionDebugger("fact", false); public static void main(String args[]){ System.out.println(fact(Integer.parseInt(args[0])));} public static int fact(int n){ hp.createNewBox(); hp.setNextParameter(""+n, "n"); hp.endParameters(); if (n==1){ hp.changeCurrentAndReturn("1"); return 1; } else{ int val=fact(n-1); hp.updateReceived(val+""); hp.changeCurrentAndReturn((n*val)+""); return (n*val); }}}
Drawing the TreeDrawing the Tree when endParameters() and
changeCurrentAndReturn() are calledEach box’s placement is relative to parent or siblingEach box contains two displacement fields
transxtransy
Future PossibilitiesFuture Possibilities
Program RewindOther language ImplementationsGlobal variablesMultiple recursive functionsCollapsible treeAutomatic Tag Insertion
ConclusionsConclusions
Met our design goalsWorks for a wide variety of recursive functions
Visualization criteriaInclude detailed text instructionsLink with instructional goals