Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

19
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way

Transcript of Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Page 1: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Problem Solving using theScience of Computing

MSE 2400 EaLiCaRA

Spring 2015 Dr. Tom Way

Page 2: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Problem Decomposition

• Breaking a problem down into smaller and smaller steps until each step can be accomplished

• Putting the solutions of each small step back together to solve the original problem

MSE 2400 Evolution & Learning 2

Page 3: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

What is Programming

• Program – a very specific set of instructions (or command lines) that make a computer do what you want it to do

• Programming – the process of creating a program– the development of a solution to an identified

problem, and setting up of a related series of instructions which, when directed through computer hardware, will produce the desired results

MSE 2400 Evolution & Learning 3

Page 4: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Steps in program development

1. Define the problem2. Outline the solution3. Develop the outline into an algorithm4. Test the algorithm for correctness5. Code the algorithm into a specific

programming language6. Run the program on the computer7. Document and maintain the program

MSE 2400 Evolution & Learning 4

Page 5: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Define the Problem

• Divide the problem into three components

(called IPO):– Inputs – what do you have?– Outputs – what do you want to have?– Processing

• how do you go from inputs to outputs?

• A defining diagram is recommended

MSE 2400 Evolution & Learning 5

Page 6: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Outline the Solution

• The major processing steps involved

• The major subtasks (if any)

• The major control structures (e.g. repetition loops)

• The major variables and record structures

• The mainline logic

MSE 2400 Evolution & Learning 6

Page 7: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Develop the Outline into an Algorithm

• Algorithm is a set of precise steps that describe exactly the tasks to be performed, and the order in which they are to be carried out

• Pseudocode (a form of structured English) is used to represent the solution algorithm

MSE 2400 Evolution & Learning 7

Page 8: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Test the Algorithm for Correctness

• The main purpose of desk checking the algorithm is to identify major logic errors early, so that they may be easily corrected

• Test data needs to be walked through each step in the algorithm, to check that the instructions described in the algorithm will actually do what they are supposed to

MSE 2400 Evolution & Learning 8

Page 9: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Code the Algorithm into a Specific Programming Language

• Only after all design considerations have been

met should you actually start to code the

program into your chosen programming

language (e.g. Python, Visual Basic, Java, C++)

MSE 2400 Evolution & Learning 9

Page 10: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Run the Program on the Computer

• This step uses a program compiler and programmer-designed test data to machine test the code for syntax errors

• Program complier translate high-level languages (e.g. VB) to low-level machine language before execution

MSE 2400 Evolution & Learning 10

Page 11: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Document and Maintain the Program

• Not the last step in the program development

process

• An ongoing task from the initial definition of the

problem to the final test result

• Involves both external documentation (such as

hierarchy charts) and internal documentation

that may have been coded in the program

MSE 2400 Evolution & Learning 11

Page 12: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

12

An Algorithm is . . .

• instructions for solving a problem in a finite amount of time using a finite amount of data

MSE 2400 Evolution & Learning

Page 13: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

13

A Program is . . .

• an algorithm written for a computer that defines classes of objects and orchestrates their interactions to solve a problem

• objects work together to create an application (or program) that solves a problem

MSE 2400 Evolution & Learning

Page 14: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

14

Code is . . .

• the product of translating an

algorithm into a programming

language • instructions for a computer that are

written in a programming language

MSE 2400 Evolution & Learning

Page 15: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

15

Programming Shortcut?

THINKINGCODE

TEST

PROBLEM-SOLVING PHASE

IMPLEMENTATION PHASE

Shortcut?

Algorithm

Code

Problem

MSE 2400 Evolution & Learning

Page 16: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

16

Problem Solving Techniques

• ASK QUESTIONS -- about the data, the process, the output, error conditions

• LOOK FOR FAMILIAR THINGS -- certain situations arise again and again

• SOLVE BY ANALOGY -- it may give you a place to start

• USE MEANS-ENDS ANALYSIS -- Determine the I/O and then work out the details

MSE 2400 Evolution & Learning

Page 17: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

17

More Problem Solving Techniques

• DIVIDE AND CONQUER -- break up large problems into manageable units

• BUILDING-BLOCK APPPROACH -- can you solve small pieces of the problem?

• MERGE SOLUTIONS -- instead of joining them end to end to avoid duplicate steps

• OVERCOME MENTAL BLOCK -- by rewriting the problem in your own words

MSE 2400 Evolution & Learning

Page 18: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

18

Sample Problem

• A programmer wants to count the number of words in a text file

MSE 2400 Evolution & Learning

Page 19: Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.

Count Words in File

• Steps?

MSE 2400 Evolution & Learning 19