1 / 33

The Visual Debugger for Recursive Functions

The Visual Debugger for Recursive Functions. By Charles Nogee Advisor: Dr. Bonomo. Introduction. Goal: A visual representation of recursive functions Uses: Debugging Pedagogical. Definitions. Program Programming Language Compilers/Compile time Runtime Errors Compile time

asa
Download Presentation

The Visual Debugger for Recursive Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Visual Debugger for Recursive Functions By Charles Nogee Advisor: Dr. Bonomo

  2. Introduction • Goal: • A visual representation of recursive functions • Uses: • Debugging • Pedagogical

  3. Definitions • Program • Programming Language • Compilers/Compile time • Runtime • Errors • Compile time • Run time • Logical

  4. Debugging Steps • Recognize error • Find the error in the code • Determine how that spot relates to program

  5. Debugger Evolution • Command Line driven • Text for the names and values of variables • Keyboard Input/Text Output • Various breakpoints • Single Stepping • Graphic User Interface (GUI) • Show the code executing • Reveal values of variables by clicking on them • Still just names and values of variables

  6. Current Debuggers • GNU Debugger • DDD • JTracer • SwingDebugger

  7. Visualization • Sight provides the most understanding • For Effective Visualization (Stasko, et al., 93) • Include detailed text instructions • Link with instructional goals • Perform user testing • Include rewind/replay functions

  8. Recursion • A recursive function is one that can call itself • Breaks large problems into small problems • Base cases • Taught early in computer science courses • Taught at Westminster in CS 152, the second CS course

  9. n!=n*(n-1)*(n-2)*…*3*2*1 In recursive form n!=1 if n=1 n!=n*(n-1)! if n>1 In Computer Code Factorial(n){ If(n==1) Return 1; else return n*factorial(n-1); } Factorial Example

  10. 4*Factorial(3) 3*Factorial(2) 2*Factorial(1) 1 2 6 2*1 3*2 24 4*6 Factorial Example Factorial(4)

  11. Fibonacci Sequence • 0,1,1,2,3,5,8,13,21,34,55,89,144… • The next number is the previous two added • Fib(n){ • if(n=0) • return 0; • else if (n=1) • return 1; • else • return Fib(n-1)+Fib(n-2); }

  12. Typical problems using recursion • Missing, incorrect, or too exclusive base case • Factorial can only work for nonnegative integers • Exorbitant and repetitive branching • Fibonacci requires calculations to be repeated.

  13. The Recursive Debugger • Goal-Visually depict recursive functions • Use of tree structure • Downward branching • Outward branching • Function Box • Parameters, Return values, Received values

  14. RecursionDebugger Class • Software to create, update, and maintain display window • Evolved over 2 semesters • Command line based • GUI based • Requires tags to be inserted in user’s code

  15. Tags • Three classes • Create instance • Gather parameters • Gather return and received values

  16. 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); • }}}

  17. Factorial 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); • }}}

  18. Debugger Window

  19. Example Displays-Factorial

  20. Example Displays-MergeSort

  21. Example Displays-N Queens

  22. OpenGL for Java • Debugger required graphics package • OpenGL chosen • Jogl was chosen due to ease of use

  23. Tree Storage • Arrays-too much mapping • Binary tree-not enough children • Three Pointer method-parent, first child, next sibling

  24. Drawing the Tree • when endParameters() and changeCurrentAndReturn() are called • Each box’s placement is relative to parent or sibling • Each box contains two displacement fields • transx • transy

  25. Updating Translation

  26. Updating Translation 2

  27. Updating Translation 3

  28. Updating Translation 4

  29. LetterDrawer Class • Jogl lacked text drawing abilities • Implemented class to use OpenGL to draw letters • Translates to appropriate spot • addChar() • Done for parameters, return values, received values

  30. User Features • Step • Run Through • Current Path • Arrow Keys • Center Window

  31. This is where you do the demonstration, Chuck

  32. Future Possibilities • Program Rewind • Other language Implementations • Global variables • Multiple recursive functions • Collapsible tree • Automatic Tag Insertion

  33. Conclusions • Met our design goals • Works for a wide variety of recursive functions • Visualization criteria • Include detailed text instructions • Link with instructional goals

More Related