Problem Solving Skill Area 305.1

Slides:



Advertisements
Similar presentations
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,
Advertisements

CMSC 104, Version 8/061L04Algorithms1.ppt Algorithms, Part 1 of 3 Topics Definition of an Algorithm Algorithm Examples Syntax versus Semantics Reading.
Programming Types of Testing.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 1 Program Design
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Chapter 3 Planning Your Solution
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Simple Program Design Third Edition A Step-by-Step Approach
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Chapter 3 Developing an algorithm. Objectives To introduce methods of analysing a problem and developing a solution To develop simple algorithms using.
School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Developing an Algorithm
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Algorithms, Part 1 of 3 Topics  Definition of an Algorithm  Algorithm Examples  Syntax versus Semantics Reading  Sections
Chapter 1 Program design Objectives To describe the steps in the program development process To introduce the current program design methodology To introduce.
Programming with Visual C++: Concepts and Projects Chapter 2B: Reading, Processing and Displaying Data (Tutorial)
1 Program Planning and Design Important stages before actual program is written.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
1 UMBC CMSC 104, Section Fall 2002 Algorithms, Part 1 of 3 Topics Definition of an Algorithm Algorithm Examples Syntax versus Semantics Reading.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.
Introduction to Computing Science and Programming I
Algorithms and Problem Solving
Algorithms, Part 1 of 3 The First step in the programming process
Algorithms, Part 1 of 3 Topics Definition of an Algorithm
Programming Languages
Component 1.6.
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Chapter 2: Input, Processing, and Output
7 - Programming 7P, Q, R - Testing.
DDC 1023 – Programming Technique
GC211Data Structure Lecture2 Sara Alhajjam.
Algorithms I: An Introduction to Algorithms
Lecture 2 Introduction to Programming
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Algorithm and Ambiguity
2008/09/17: Lecture 4 CMSC 104, Section 0101 John Y. Park
Unit# 9: Computer Program Development
Program Design Introduction to Computer Programming By:
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Funamental slides
1) C program development 2) Selection structure
Chapter 2- Visual Basic Schneider
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Algorithm and Ambiguity
Algorithms and Problem Solving
Algorithms, Part 1 of 3 Topics Definition of an Algorithm
Programming Fundamentals (750113) Ch1. Problem Solving
Software Development Process
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Flowcharts and Pseudo Code
Programming Fundamentals (750113) Ch1. Problem Solving
Chapter 2: Input, Processing, and Output
Basic Concepts of Algorithm
WJEC GCSE Computer Science
WJEC GCSE Computer Science
Algorithms, Part 1 of 3 Topics Definition of an Algorithm
CHAPTER 6 Testing and Debugging.
Presentation transcript:

Problem Solving Skill Area 305.1 Materials Prepared by Dhimas Ruswanto, BMm Skill Area 305.1 Problem Solving

Lecture Overview Problem Solving Algorithm Dry Run

PROBLEM SOLVING Problem-Solving methodology: Define the problem Outline the solution Develop an algorithm Test the algorithm

DEFINE THE PROBLEM Have a thorough understanding of the problem State the problem in clear and concise terms to avoid any confusion or misunderstanding Examples: Calculate the sum and the average of two numbers 25 & 45

OUTLINE THE SOLUTION The problem can be divided into three components: Inputs – What do you have? Outputs – What do you want to have? Processing – How do you go from inputs to outputs? Examples: Calculate the sum and the average of two numbers 25 & 45

OUTLINE THE SOLUTION (cont’d) Inputs = First number = a = 25 Second number = b = 45 Outputs = sum average Processing = sum = a +b Average = a+b 2

ALGORITHM An algorithm is a written step by step solution to a problem. Why bother writing an algorithm? For your own use in the future. You won’t have to rethink the problem. So others can use it, even if they know very little about the principles behind how the solution was derived

ALGORITHM (cont’d) An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity. GOAL: To find a single set of instructions that can be used to solve any problem of a particular type (a general solution).

EXAMPLE OF ALGORITHM ¢ MAKE A CALL

EXAMPLES OF ALGORITHM

ALGORITHM REPRESENTATION Syntax: The grammar of the language The way in which we construct sentences by following principles and rules Semantics: The meaning The interpretations of and meanings derived from the sentence transmission and understanding of the message

SYNTAX AND SEMANTIC Sentence : “Baby milk drinks” Does not have a syntactic meaning But through semantics most people would interpret it as meaning “Baby drinks milks”, therefore we can find a meaning from key words.

SYNTAX AND SEMANTIC (CONT’D) In programming language: Syntax defines how logical entities expressed in characters Semantics describe the logical entities of a programming language and their interactions Examples: x = 0 - 1; y = - 1; the syntax for the "-" token is the same, but, it has a different meaning ("semantic), depending where its used. In the "x" assignment, "-" means the "subtraction" operation, In the "y" assignment, "-" means the "negative sign" operation.

DEVELOP AN ALGORITHM Decompose the problem into simpler steps and expresses the solution in terms of actions to be executed order in which these actions are to be executed Examples: Calculate the sum and the average of two numbers 25 & 45

DEVELOP AN ALGORITHM (CONT’D) Declare two variables, a and b Initialise both variables to 0 a= 0, b= 0 Ask user to enter first number Assign user input to a variable Ask user to enter second number Assign user input to second b variable Add first num to second num Print the sum Divide the sum by 2 Print the average

TEST THE ALGORITHM The programmer must make sure that the algorithm is correct. The objective is to identify major logic errors early, so that they may be easily corrected. Test data should be applied to each step, to check whether the algorithm actually does what it is supposed to.

DRY RUN You can test your program without using a computer by dry running it on paper Dry runs involves the execution of code segments. You act as the computer – following the instructions of the program, recording the valves of the variables at each stage You can do this with a table

DRY RUN (Cont’d) The table with have column headed with the names of the variables in the program Each row in the table will be labelled with a line number form the program. The entries of each row in the table will be values of the variables after the execution of the statement on that line You don’t need a row for every line in the program, just those lines where some significant change to the state of the program occurs e.g a variable gets a new value

DRY RUN (Cont’d) In this table you can record all relevant changes to the variables as the program progresses, thereby test the logic of the program / algorithm Do a dry run before you code your program on computer this way any logic errors will come to light during the dry run

Example of DRY RUN L1 Declare two variables, a and b L2 Initialise both variables to 0 L3 a= 0, b= 0 L4 Ask user to enter first number L5 Assign user input to a variable L6 Ask user to enter second number L7 Assign user input to second b variable L8 Add first num to second num L9 Print the sum L10 Divide the sum by 2 L11 Print the average Do a Dry run for this program assuming the user enters 18 for first number and 24 for the second

A Sample of DRY RUN table After execution First num Second num Sum Average Line 2 Line 5 18 Line 7 24 Line 8 42 Line 10 21

SUMMARY An algorithm is a finite set of unambiguous, executable instructions that directs a terminating activity. Syntax: The grammar of the language Semantics: The meaning Dry runs involves the execution of code segments.