Problem Solving and Algorithm Design

Slides:



Advertisements
Similar presentations
Low-Level Programming Languages and Pseudocode
Advertisements

Problem Solving and Algorithm Design
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
1 Algorithms Algorithm A set of unambiguous instructions for solving a problem or subproblem in a finite amount of time using a finite amount of data Why.
Low-Level Programming Languages and Pseudocode Chapter 6.
Slides modified by Erin Chambers Problem Solving and Algorithm Design.
Programming Dr. Abraham Most slides are from your textbook.
Chapter 6 Problem Solving and Algorithm Design. 2 Phase Interactions.
Low-Level Programming Languages and Pseudocode Chapter 6.
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. 2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Problem Solving and Algorithms
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
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
Computer Science 1620 Loops.
Chapter 2: Algorithm Discovery and Design
Algorithms and Problem Solving
Chapter 1 Introduction to Object- Oriented Programming and Problem Solving.
Program Design and Development
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
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.
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Programming Fundamentals (750113) Ch1. Problem Solving
Problem Solving and Algorithm Design
BBS Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code.
Chapter 2: Algorithm Discovery and Design
Slides modified by Erin Chambers Problem Solving and Algorithm Design, part 2.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Low-Level Programming Languages and Pseudocode
CPS 120: Introduction to Computer Science
An ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time Let's examine the four parts of this.
Quiz # 2 Chapters 4, 5, & 6.
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
Problem Solving and Algorithms
Invitation to Computer Science, Java Version, Second Edition.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing, or unsettled.
CS 1308 Computer Literacy and The Internet Software.
Chapter 6 Problem Solving and Algorithm Design. 2 Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing,
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Chapter 6 Problem Solving and Algorithm Design. 2 Chapter Goals Apply top-down design methodology to develop an algorithm to solve a problem Define the.
Chapter 2 Pseudocode. Objectives To introduce common words, keywords and meaningful names when writing pseudocode To define the three basic control structures.
ITEC113 Algorithms and Programming Techniques
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
CSCI-100 Introduction to Computing
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
Chapter 6 Problem Solving and Algorithm Design. 2 Chapter Goals Determine whether a problem is suitable for a computer solution Describe the computer.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
Algorithms and Pseudocode
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Low-Level Programming Languages, Pseudocode and Testing Chapter 6.
Algorithms Sept 4, Tuesday’s Lab You developed an algorithm Input – an 8 ½ x 11 inch piece of paper Audience – Fellow classmates Process – Instructions.
ALGORITHMS AND FLOWCHARTS
Problem Solving and Algorithms
Chapter 4: Algorithm Design
Introduction to pseudocode
Programming Fundamentals (750113) Ch1. Problem Solving
Problem Solving and Algorithm Design
Chapter 4: Algorithm Design
Programming We have seen various examples of programming languages
Algorithm and Ambiguity
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
The structure of programming
Thinking procedurally
Presentation transcript:

Problem Solving and Algorithm Design Chapter 6 Problem Solving and Algorithm Design

Problem Solving Problem solving The act of finding a solution to a perplexing, distressing, vexing, or unsettled question How do you define problem solving?

Problem Solving How do you solve problems? Understand the problem Devise a plan Carry out the plan Look back

Strategies Ask questions! 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?

Strategies Ask questions! Never reinvent the wheel! Similar problems come up again and again in different guises A good programmer recognizes a task or subtask that has been solved before and plugs in the solution Can you think of two similar problems?

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

Algorithms Algorithm A set of unambiguous instructions for solving a problem or subproblem in a finite amount of time using a finite amount of data

Phase Interactions (What happens if the problem is revised?) Should we add another arrow? (What happens if the problem is revised?)

Pseudocode Pseudocode A mixture of English and formatting to make the steps in an algorithm explicit Algorithm to Convert base-10 number to other bases While ( the quotient is not zero ) Divide the decimal number by the new base Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient

Following an Algorithm Figure 6.4 A recipe for Hollandaise sauce

Following an Algorithm Algorithm for preparing a Hollandaise sauce If concerned about cholesterol Put butter substitute in a pot Else Put butter in a pot Turn on burner Put pot on the burner While (NOT bubbling) Leave pot on the burner Put other ingredients in the blender Turn on blender While (more in pot) Pour contents into lender in slow steam Turn off blender

Developing an Algorithm Two methodologies used to develop computer solutions to a problem Top-down design focuses on the tasks to be done Object-oriented design focuses on the data involved in the solution But first, let's look at a way to express algorithms: pseudocode

Following Pseudocode While ( the quotient is not zero ) Divide the decimal number by the new base Make the remainder the next digit to the left in the answer Replace the original decimal number with the quotient What is 93 in base 8? 93/8 gives 11 remainder 5 11/8 gives 1 remainder 3 1/ 8 gives 0 remainder 1 answer 1 3 5

Easier way to organize solution Following Pseudocode Easier way to organize solution

Pseudocode for Complete Computer Solution Write "Enter the new base" Read newBase Write "Enter the number to be converted" Read decimalNumber Set quotient to 1 While (quotient is not zero) Set quotient to decimalNumber DIV newBase Set remainder to decimalNumber REM newBase Make the remainder the next digit to the left in the answer Set decimalNumber to quotient Write "The answer is " Write answer

Pseudocode Functionality Variables Names of places to store values quotient, decimalNumber, newBase Assignment Storing the value of an expression into a variable Set quotient to 64 quotient <-- 64 quotient <-- 6 * 10 + 4

Pseudocode Functionality Output Printing a value on an output device Write, Print Input Getting values from the outside word and storing them into variables Get, Read

Pseudocode Functionality Repetition Repeating a series of statements Set count to 1 While ( count < 10) Write "Enter an integer number" Read aNumber Write "You entered " + aNumber Set count to count + 1 How many values were read?

Pseudocode Functionality Selection Making a choice to execute or skip a statement (or group of statements) Read number If (number < 0) Write number + " is less than zero." or Write "Enter a positive number." Write "You didn't follow instructions."

Pseudocode Functionality Selection Choose to execute one statement (or group of statements) or another statement (or group of statements) If ( age < 12 ) Write "Pay children's rate" Write "You get a free box of popcorn" else If ( age < 65 ) Write "Pay regular rate" else Write "Pay senior citizens rate"

Pseudocode Example Write "How many pairs of values are to be entered?" Read numberOfPairs Set numberRead to 0 While (numberRead < numberOfPairs) Write "Enter two values separated by a blank; press return" Read number1 Read number2 If (number1 < number2) Print number1 + " " + number2 Else Print number2 + " " number1 Increment numberRead

Walk Through Data Fill in values during each iteration 3 numberRead number1 number2 55 70 2 1 33 33 numberOfPairs What is the output?