Chapter 6: Algorithmic Problem Solving 1 Chapter 6 Algorithmic Problem Solving.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

PSEUDOCODE & FLOW CHART
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
CS1010 Programming Methodology
 Control structures  Algorithm & flowchart  If statements  While statements.
ITEC113 Algorithms and Programming Techniques
Standard Algorithms. Many algorithms appear over and over again, in program after program. These are called standard algorithms You are required to know.
Computer Science 1620 Loops.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts and Debugging.
Program Design and Development
Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart.
Computer Science 1620 Programming & Problem Solving.
1 CSE1301 Computer Programming: Lecture 15 Flowcharts, Testing and Debugging.
Chapter 1 Program Design
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Repetition Statements.
Pseudocode.
Chapter 3 Planning Your Solution
CS1101: Programming Methodology Aaron Tan.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
CIS Computer Programming Logic
Introduction to Computer & C Computers Computers are programmable machines capable of performing calculations Examples of special-purpose computers are.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
CSE 102 Introduction to Computer Engineering What is an Algorithm?
Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
An Introduction to Programming with C++ Sixth Edition Chapter 7 The Repetition Structure.
Control Structures II Repetition (Loops). Why Is Repetition Needed? How can you solve the following problem: What is the sum of all the numbers from 1.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Visual Basic Programming
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Programming, an introduction to Pascal
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
Computer Programming Control Structure
Agenda Perform Quiz #1 (20 minutes) Loops –Introduction / Purpose –while loops Structure / Examples involving a while loop –do/while loops Structure /
17 November 2015Birkbeck College, U. London1 Introduction to Computer Systems Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
The Hashemite University Computer Engineering Department
Agenda  Take up homework  Loops - Continued –For loops Structure / Example involving a for loop  Storing Characters in variables  Introduction to Functions.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
R. Johnsonbaugh, Discrete Mathematics 5 th edition, 2001 Chapter 3 Algorithms.
Application: Algorithms Lecture 19 Section 3.8 Tue, Feb 20, 2007.
CS1010: Programming Methodology
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Quiz1 Question  Add Binary Numbers a) b) c) d) e) none
1 CSE1301 Computer Programming: Lecture 16 Flow Diagrams and Debugging.
Chapter 5: Preparing C Programs
Introduction to Algorithms
CS1010 Programming Methodology
Introduction to Programming
Chapter 4 – Control Structures Part 1
CSS161: Fundamentals of Computing
Structured Program
1) C program development 2) Selection structure
Chapter 3 - Structured Program Development
Algorithm Discovery and Design
Algorithm Discovery and Design
Chapter 3 - Structured Program Development
Introduction to Algorithms
Application: Algorithms
Application: Algorithms
Introduction to Computer Programming IT-104
Presentation transcript:

Chapter 6: Algorithmic Problem Solving 1 Chapter 6 Algorithmic Problem Solving

Chapter 6Algorithm2 Algorithm: a well defined computational procedure consisting of a set of instructions, that takes some value(s) as input, and produces some value(s), as output. Al-Khowarizmi  Algorismus  Algorithm

Chapter 6Algorithm3 InputOutputAlgorithm

Chapter 6Algorithm4 Understanding the problem Writing an algorithm Converting to code Verifying the algorithm qAlgorithm embeds logic of solution. qAlgorithm is converted to program. qAlgorithmic problem solving: uwriting an algorithm -- tough utranslate algorithm to code -- easy

Chapter 6Software and hardware5 qSoftware: algorithms, programs. qHardware: computers (CPU, disk drive, keyboard, etc.) recipe (software) Cooking utensils (hardware) : ingredients bah kut teh

Chapter 6Euclidean algorithm6 qFirst documented algorithm by Euclid (300 B.C.) to compute greatest common divisor (gcd). Examples: gcd(3,21) = 3; gcd(15,40) = 5. 1.Let A and B be integers with A > B  0. 2.If B = 0, then the gcd is A and the algorithm ends. 3.Otherwise, find q and r such that A = qB + r where 0  r < B Note that we have 0  r < B < A and gcd(A,B) = gcd(B,r). Replace A by B, B by r. Go to step 2.

Chapter 6Euclidean algorithm7 qWalk through the algorithm with examples: A = 40, B =15. A = 2B + 10  A = 15 ; B = 10 A = 1B + 5  A = 10 ; B = 5 A = 2B + 0  A = 5 ; B = 0 gcd is 5 1.Let A and B be integers with A > B  0. 2.If B = 0, then the gcd is A and the algorithm ends. 3.Otherwise, find q and r such that A = qB + r where 0  r < B Note that we have 0  r < B < A and gcd(A,B) = gcd(B,r). Replace A by B, B by r. Go to step 2.

Chapter 6Data types and structures8 qData types: integer, real number, character, Boolean, pointer, etc. Examples: 32, , 'a', true. qData structures: arrays, records, files, etc. Program = Algorithm + Data Structures qData are stored in variables in a program. Variables take up memory space in the computer.

Chapter 6A C program9 qA sample C program /* A simple C program to read a number & compute and display its square by using the multiplication (*) operator. */ #include main () /* a C program always has a main function */ { int n; /* this declares an integer variable 'n' */ printf ("\nEnter the number to be squared: "); scanf ("%d", &n); printf ("Using the * operator, the square of %d is %d.\n\n", n, n*n); }

Chapter 6Characteristics of an algorithm10 Characteristics of an algorithm qEach step must be exact. qMust terminate. qMust be effective. qMust be general.

Chapter 6Pseudo-code11 Pseudo-code qHow to represent an algorithm? uPseudo-code uFlowchart qPseudo-code: a combination of English text, mathematical notations, and keywords from the programming language.

Chapter 6Pseudo-code12 Pseudo-code qTo find average, min and max among a list. First, you initialise sum to zero, min to a very big number, and max to a very small number. Then, you enter the numbers, one by one. For each number that you have entered, assign it to num and add it to the sum. At the same time, you compare num with min, if num is smaller than min, let min be num instead. Similarly, you compare num with max, if num is larger than max, let max be num instead. After all the numbers have been entered, you divide sum by the numbers of items entered, and let ave be this result. End of algorithm.

Chapter 6Pseudo-code13 Pseudo-code qTo find average, min and max among a list. sum  count  0{ sum = sum of numbers; count = how many numbers are entered? } min  ?{ min to hold the smallest value eventually } max  ?{ max to hold the largest value eventually } for each num entered, increment count sum  sum + num if num < min then min  num if num > max then max  num ave  sum/count

Chapter 6Pseudo-code14 Flowchart qDiagrammatic form: uterminator uconnector uprocess box udecision box

Chapter 6Pseudo-code15 Flowchart qTo find minimum and maximum among a list. start sum  count  0 min  ? max  ? end of input? increment count sum  sum + num num<min? num>max? min  num Yes No ave  num/count A A end Yes max  num Yes No

Chapter 6Control structures16 Control structures qSequence uimplied; one after another qBranching (selection) uselect alternative path based on condition (true/false) uexample: if x  0 then a = b/x; if tired then rest else work;

Chapter 6Control structures17 Control structures qLoop (repetition) ubounded loop: for x = 1 to 10 do { statements }; uunbounded loop: while (condition) do { statements }; urepeat/iterate statements in loop body until condition changes umust make sure loop terminates

Chapter 6Homework18 Homework Try exercises behind chapter 6.