Dry Runs and Trace Tables

Slides:



Advertisements
Similar presentations
Basics of Recursion Programming with Recursion
Advertisements

More on Psuedo-Code Sangeetha Parthasarathy 1/23/01.
Dry Run You can test your program without using a computer by dry running it on paper You act as the computer – following the instructions of the program,
Desk Checking. Desk checking is a manual (non computerised) technique for checking the logic of an algorithm. The person performing the desk check effectively.
How SAS implements structured programming constructs
Microsoft® Small Basic
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
CS107 Introduction to Computer Science Lecture 2.
Repetition Control Structures School of Business Eastern Illinois University © Abdou Illia, Spring 2003 (Week 9, Friday 3/07/2003)
Programming Types of Testing.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Iteration This week we will learn how to use iteration in C++ Iteration is the repetition of a statement or block of statements in a program. C++ has three.
1 Module 12 Computation and Configurations –Formal Definition –Important Terms –Examples.
Program Design and Development
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
CSI 101 Elements of Computing Spring 2009 Lecture #5 Designing with Pseudocode Wednesday, February 4th, 2009.
Programming Epson Robots – Part 2 ME 4135 – Fall 2012 Dr. R. Lindeke.
Computer Science 101 Circuit Design Algorithm. Circuit Design - The Problem The problem is to design a circuit that accomplishes a specified task. The.
CC0002NI – Computer Programming Computer Programming Er. Saroj Sharan Regmi Week 7.
Algorithmic Recursion. Recursion Alongside the algorithm, recursion is one of the most important and fundamental concepts in computer science as well.
Repetition & Loops. One of the BIG advantages of a computer: ­It can perform tasks over and over again, without getting bored or making mistakes (assuming.
ANALYSIS AND ALGORITHM DESIGN - IV. Repeat statements/looping/counting/iterations It is often necessary to repeat certain parts of a program a number.
CSE 501N Fall ‘09 12: Recursion and Recursive Algorithms 8 October 2009 Nick Leidenfrost.
Computer Science 101 Circuit Design - Examples. Sum of Products Algorithm Identify each row of the output that has a 1. Identify each row of the output.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Chapter 6 Looping CS185/09 - Introduction to Programming Caldwell College.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Recursive Algorithms &
A loop is a repetition control structure. body - statements to be repeated control statement - decides whether another repetition needs to be made leading.
Repetition and Iteration ANSI-C. Repetition We need a control instruction to allows us to execute an statement or a set of statements as many times as.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
CSCI-100 Introduction to Computing
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
1 Recursion Recursion is a powerful programming technique that provides elegant solutions to certain problems. Chapter 11 focuses on explaining the underlying.
5 While-Statements © 2010 David A Watt, University of Glasgow Accelerated Programming 2 Part I: Python Programming.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
Introduction to Recursion. Recursion Defined A procedure or function which calls itself. Powerful mechanism for repetition. Makes algorithms more compact.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
ITERATION. Iteration Computers are often used to automate repetitive tasks. Repeating identical or similar tasks without making errors is something that.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Fourth Quarter.  Involves loops or cycles ◦ Loops: means that a process may be repeated as long as certain condition remains true or remains false. ◦
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
Control Structures: Examples. for-loop example Q: If a=1, b=3, and x=7, what is the value of x when the loop terminates? A: x=1 for(k=a; k
GC211Data Structure Lecture2 Sara Alhajjam.
PROGRAM CONTROL STRUCTURE
Chapter 2.3 Binary Logic.
ALGORITHMS & FLOWCHARTING II
Sit-In Lab 1 Ob-CHESS-ion
Java Software Structures: John Lewis & Joseph Chase
LOOPS.
Computer Programming.
Repetition Chapter 6 12/06/16 & 12/07/16 1 1
Chapter 12 Recursion (methods calling themselves)
Control Structure Senior Lecturer
Program Design Introduction to Computer Programming By:
Topic 1: Problem Solving
Problem Solving Skill Area 305.1
Computer Science Core Concepts
CHAPTER 4 Iterative Structure.
Recursion Chapter 11.
Basic Concepts of Algorithm
Desk Checking.
Presentation transcript:

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. 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 ).

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.

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.

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

number triangular_value value PRINT - READ 5  FOR 1 2 3 6 4 10 15

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

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