CPS 120: Introduction to Computer Science

Slides:



Advertisements
Similar presentations
Problem Solving and Algorithm Design
Advertisements

CS 240 Computer Programming 1
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
How Are Algorithms Developed?
6-1 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer problem-solving process and relate it to Polya’s.
Problem Solving and Algorithm Design
Chapter 6 Problem Solving and Algorithm Design. 6-2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Chapter 1 - An Introduction to Computers and Problem Solving
Introduction to Programming
Chapter 2 - Problem Solving
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Reference :Understanding Computers
Chapter 2 - Problem Solving
زبانهای برنامه سازی برنامه سازی پیشرفته ارائه دهنده دکتر سيد امين حسيني E.mail: Home page:
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
Algorithms and Problem Solving-1 Algorithms and Problem Solving Mainly based on Chapter 6: “Problem Solving and Algorithm Design” from the Book: “Computer.
ITEC113 Algorithms and Programming Techniques
Chapter 2- Visual Basic Schneider
Algorithms and Problem Solving
Lecture Notes 1/21/04 Program Design & Intro to Algorithms.
Chapter 6 Problem Solving and Algorithm Design Nell Dale John Lewis.
6-1 Problem Solving Problem solving is the act of finding a solution to a perplexing, distressing, vexing, or unsettled question.
Understanding the Mainline Logical Flow Through a Program (continued)
Chapter 2: Developing a Program Extended and Concise Prelude to Programming Concepts and Design Copyright © 2003 Scott/Jones, Inc.. All rights reserved.
Chapter 1 Program Design
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Problem Solving and Algorithm Design
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Chapter 3 Planning Your Solution
The Program Design Phases
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Developing a Program.
Simple Program Design Third Edition A Step-by-Step Approach
Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing, or unsettled.
CPS120: Introduction to Computer Science Midterm Exam Review.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
Programming Concepts Chapter 3.
CS 1308 Computer Literacy and The Internet Software.
Chapter 1 Introduction to Structured Design. Introduction  System  A combination of people, equipment, and procedures that work together to perform.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
ALGORITHM List of instructions for carrying out some process step by step. A sequence of instructions which has a clear meaning and can performed with.
ITEC113 Algorithms and Programming Techniques
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
CPS120: Introduction to Computer Science Midterm Exam Review.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
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.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
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.
CPS120: Introduction to Computer Science Session 5.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Chapter 2- Visual Basic Schneider
Lecture 2 Introduction to Programming
Introduction to Computer Programming
Unit# 9: Computer Program Development
Problem Solving and Algorithm Design
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
Problem Solving and Algorithm Design
CPS120: Introduction to Computer Science
Chapter 2- Visual Basic Schneider
Programming We have seen various examples of programming languages
How Are Algorithms Developed?
Basic Concepts of Algorithm
Programming Logic and Design Eighth Edition
Presentation transcript:

CPS 120: Introduction to Computer Science Algorithm Design and Problem Solving

Session Goals Determine whether a problem is suitable for a computer solution Describe the computer problem-solving process Distinguish between following an algorithm and developing one Apply top-down design methodology to develop an algorithm to solve a problem

The Program Development Cycle Analyze the problem Design the solution algorithm Design the user interface Write the code Test and debug the program Complete the documentation

Problem Solving Problem solving is the act of finding a solution to a perplexing, distressing, vexing, or unsettled question

Problem Solving In 1945 George Polya wrote How to Solve It: A New Aspect of Mathematical Method His How to Solve It list is quite general Written in the context of solving mathematical problems The list becomes applicable to all types of problems

Ask Questions... …to understand the problem What do I know about the problem? What is the information that I have to process in order the find the solution? What does the solution look like? What sort of special cases exist? How will I recognize that I have found the solution? Flowcharting and Pseudocode

Look for Familiar Things You should never reinvent the wheel In computing, you see certain problems again and again in different guises A good programmer sees a task, or perhaps part of a task (a subtask), that has been solved before and plugs in the solution Functions and subroutines

Divide and Conquer Break up a large problem into smaller units that we can handle Applies the concept of abstraction The divide-and-conquer approach can be applied over and over again until each subtask is manageable Modularization

Computer Problem-Solving The computer problem-solving process

The Interactions Between Problem-Solving Phases

The Program Development Cycle Analyze the problem Design the solution algorithm Design the user interface Write the code Test and debug the program Complete the documentation

Algorithms Muhammad ibn Musa Al'Khowarizmi, a Tashkent cleric who in the twelfth century developed the concept of a written process to be followed to achieve some goal, and published a book on the subject that gave it is modern name -- algorithm.

What is an Algorithm? An algorithm is merely the sequence of steps taken to solve a problem Two parts Actions to be executed Order in which those actions are to be done Computational steps that transform the input data into useful output data. Algorithms are not programs They need to be coded in a programming language like C++, Visual Basic, COBOL, Java, etc. The logical sequence of steps

Algorithms An algorithm is set of instructions for solving a problem or sub-problem in a finite amount of time using a finite amount of data The instructions are unambiguous

Following an Algorithm Preparing a Hollandaise sauce

Following an Algorithm (cont.) Preparing a Hollandaise sauce

Programs are Solutions to Problems Programmers arrive at these solutions by using one or more of these devices: Structured Programming Structure charts Logic flowcharts Pseudocode (sue-dough'-code) Solutions to problems need to be developed before code is written

Developing an Algorithm The plan must be suitable in a suitable form Two methodologies that currently used Top-down design Object-oriented design

Structured Programming Structured program languages lend themselves to flowcharts, structure charts, and pseudocode. Structured programming languages work best where the instructions have been broken up into small, manageable parts.

Top-Down Design Breaking the problem into a set of sub-problems called modules Creating a hierarchical structure of problems and sub-problems

Structure Charts Structure charts illustrate the structure of a program by showing independent hierarchical steps. Major divisions are subdivided into smaller pieces of information.

Top-Down Design An example of top-down design This process continues for as many levels as it takes to expand every task to the smallest details A step that needs to be expanded is an abstract step

A General Example Planning a large party Subdividing the party planning

Flowcharts and Pseudocode Forms of documentation used to build and communicate the detailed parts your structured designs

Flowchart A graphical representation of an algorithm.

Pseudocode Uses a mixture of English and formatting to make the steps in the solution explicit

Flowcharts & Pseudocode are Important A graphical layout of the algorithm is often very useful in spotting “illogical” logic! Pseudocode – Make a detailed description of your algorithm’s logic before worrying about syntax and data layout. An algorithm you develop using pseudocode should be capable of implementation in any procedural programming language Pseudocode is generally independent of the implementation language

Reasons Programmers Draw Flowcharts Drawing a flowchart gives the programmer a good visual reference of what the program will do Flowcharts serve as program documentation Flowcharts allow a programmer to test alternative solution to a problem before coding Flowcharts provide a method for easy desk checking

Logic Flowcharts These represent the flow of logic in a program and help programmers “see” program design.

Common Flowchart Symbols Terminator. Shows the starting and ending points of the program. A terminator has flow lines in only one direction, either in (a stop node) or out (a start node). Data Input or Output. Allows the user to input data and results to be displayed. Processing. Indicates an operation performed by the computer, such as a variable assignment or mathematical operation. With a heading – an internal subroutine Decision. The diamond indicates a decision structure. A diamond always has two flow lines out. One flow lineout is labeled the “yes” branch and the other is labeled the “no” branch. Predefined Process. One statement denotes a group of previously defined statements. Such as a function or a subroutine created externally Connector. Connectors avoid crossing flow lines, making the flowchart easier to read. Connectors indicate where flow lines are connected. Connectors come in pairs, one with a flow line in and the other with a flow line out. Off-page connector. Even fairly small programs can have flowcharts that extend several pages. The off-page connector indicates the continuation of the flowchart on another page. Just like connectors, off-page connectors come in pairs. Flow line. Flow lines connect the flowchart symbols and show the sequence of operations during the program execution. Common Flowchart Symbols

How to Draw a Flowchart Five steps which can be used as a guide for completing flowcharts. Start with a 'trigger' event (it may be the beginning of the program) Initialize any values that need to be defined at the start of the program Note each successive action concisely and clearly Go with the main flow (put extra detail in other charts -- this is the basis of structured programming) Follow the process through to a useful conclusion (end at a 'target' point -- like having no more records to process)

Rules for Drawing Flowcharts Top to bottom and left to right Draw the flowchart the way you like to read Use arrowheads on flow lines whenever the flow is not top to bottom, left to right Be neat ! Use graphics software Avoid intersecting lines

Sample Program Flowchart Terminal Symbol Start Initialize Variables Preparation Symbol or Variables = I/O Symbol Open Files Read a Record No More items? Process Record (Total Time) Close Files Decision Symbol Stop Yes Process Record (Detail Time) Process Symbol Write Record

Disadvantages to Flowcharts Time consuming A program flowchart shows how the input becomes output, but it does not show why a particular step is done Flowcharts are subjective

Pseudocode Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is a "text-based" detail (algorithmic) design tool. An English description of an algorithm in sufficient detail to allow its implementation to be easily written.

Pseudocode This device is not visual but is considered a “first draft” of the actual program. Pseudocode is written in the programmer’s native language and concentrates on the logic in a program—not the syntax of a programming language.

General Rules for Pseudocode There is no standard pseudocode The rules of Pseudocode are generally straightforward Should be easily read and understood by non-programmers All statements showing "dependency" are to be indented. These include while, do, for, if, switch

Writing Pseudocode You need to reach a balance between excessive and insufficient detail. Write only what is necessary to understand and communicate the essential parts of your algorithm

Pseudocode Statement Rules Statements are written in a simple English-like language Each instruction is started on a separate line Logic-showing keywords are written in UPPER CASE or typed in BOLD UPPERCASE (e.g. IF, THEN, FOR, DO etc.) These are the only uppercase words in this form of pseudocode. Indentation is used to show structure Instructions are written from top to bottom, with only one entry point and one exit point Logically related groups of instructions can be formed into modules and given a name

Pseudocode for a Generalized Program START Intialize variables LOOP While More records do READ record PROCESS record PRINT detail record ENDLOOP CALCULATE TOTALS PRINT total record END

Rules for Pseudocode Make the pseudocode language-independent Indent lines for readability Make keywords stick out by showing them capitalized, in a different color or a different font Punctuation is optional End every IF with ENDIF Begin loop with LOOP and end with ENDLOOP Show MAINLINE first; all others follow TERMINATE all routines with an END instruction

A Computer Example Problem Create an address list that includes each person’s name, address, telephone number, and e-mail address This list should then be printed in alphabetical order The names to be included in the list are on scraps of paper and business cards

A Computer Example

A Computer Example

A Computer Example

A Computer Example

A Computer Example

Relation of Flowcharts & Pseudocode

The Program Development Cycle Analyze the problem Design the solution algorithm Design the user interface Write the code Test and debug the program Complete the documentation

Data Processing Facts enter the computer They are: Checked for accuracy Organized Calculated with Stored