1 / 8

Dry Runs and Trace Tables

Dry Runs and Trace Tables. Dry Runs. An important part of the algorithm design process is that of testing the final design. To do this we carry out a dry run of the algorithm.

raven
Download Presentation

Dry Runs and Trace Tables

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. Dry Runs and Trace Tables

  2. Dry Runs An important part of the algorithm design process is that of testing the final design. To do this we carry out a dry run of the algorithm. When dry running an algorithm we select some appropriate test data and complete a full execution of the algorithm until termination is achieved ( or not, if the algorithm is incorrectly specified ).

  3. Trace Table When executing a dry run of an algorithm we record the state of the algorithm after each instruction. Generally, we define the state of an algorithm as: the contents of any variables that have been declared during the execution of the algorithm.

  4. Trace Table To record the state of an algorithm we use a trace table. When tracing a non-recursive algorithm our trace tables take the following form: • The column headings of a trace table record the names of all the variables used in the algorithm. • The rows record the state of the variables after every instruction execution.

  5. Example Dry Run the iterative algorithm that computes the triangular value of a positive number. Use the value 5 as test data. {Print triangular value of input number} PRINT “Enter a number “ READ number triangular_value  0 FOR ( value FROM 1 TO number ) triangular_value  triangular_value + value ENDFOR PRINT triangular_value

  6. Example Dry Run the recursive algorithm that computes the triangular value of a positive number. Use the value 5 as test data. Module Name: tri Inputs: n Outputs: triangular value of n Process: IF ( n = 1 ) THEN /* Base Case */ RETURN 1 ELSE /* Recursive solution */ RETURN n + tri(n-1) ENDIF

  7. n=5 5=1 ? FALSE RETURN 5+tri(4) n=4 4=1 ? FALSE RETURN 4+tri(3) n=3 3=1 ? FALSE RETURN 3+tri(2) n=2 2=1 ? FALSE RETURN 2+tri(1) n=1 1=1 ? TRUE RETURN 1

More Related