computer software & software development h&k chapter 1

27
Computer Software & Software Development H&K Chapter 1 Instructor – Gokcen Cilingir Cpt S 121 (June 20, 2011) Washington State University

Upload: glenys

Post on 14-Feb-2016

33 views

Category:

Documents


0 download

DESCRIPTION

Computer Software & Software Development H&K Chapter 1. Instructor – Gokcen Cilingir Cpt S 121 (June 20, 2011) Washington State University. Problem Solving. Problem solving is the process of transforming the description of a problem into the solution of that problem. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computer Software & Software Development H&K Chapter 1

Computer Software & Software Development

H&K Chapter 1

Instructor – Gokcen CilingirCpt S 121 (June 20, 2011)

Washington State University

Page 2: Computer Software & Software Development H&K Chapter 1

Problem Solving Problem solving is the process of transforming the

description of a problem into the solution of that problem.

We are, as human machines, are problem solving agents. We have receptors to perceive our environment, we detect problems, design problem-solving strategies and tools, apply our solutions and get output.

Steps involved in any problem solving process:◦ Get the input ◦ Calculate/Create/Perform what is needed to solve the

problem◦ Output the result

Page 3: Computer Software & Software Development H&K Chapter 1

In this class…We’re going to learn how to translate solution

strategies to given problems into C programs.

For given problems, we’re going to design sets of instructions that can be executed by a computer, which provides general solutions.

Algorithm: A sequence of instructions that solve a problem

Page 4: Computer Software & Software Development H&K Chapter 1

Greatest common divisor

Problem: Find the largest positive integer that divides the given two positive integers evenly (i.e., the greatest common divisor(GCD) ).

Solve a problem instance → math

Solve the general problem, i.e. describe the procedure to calculate GCD of any two numbers → algorithm design

Page 5: Computer Software & Software Development H&K Chapter 1

Euclid’s AlgorithmProblem: Find the largest positive integer that

divides the given two positive integers evenly(i.e., the greatest common divisor).

Algorithm:1. Assign M and N the values of the larger and

smaller of the two positive integers, respectively.2. Divide M by N and call the remainder R.3. If R is not 0, then assign M the value of N, assign N

the value of R, and return to Step 2. Otherwise, the greatest common divisor is the value currently assigned to N.

Page 6: Computer Software & Software Development H&K Chapter 1

Finding the GCD of 24 and 9 (Specific Solution)M N R

24 9 6 9 6 3 6 3 0

So, GCD of 24 and 9 is 3.

Page 7: Computer Software & Software Development H&K Chapter 1

Euclid’s Algorithm (con’t)

Do we need to know the theory that Euclid used to come up with this algorithm in order to use it?

Is this the only algorithm that solves the GCD problem?

What intelligence is required to find the GCD using this algorithm?Can you make a machine that only understands from

1s and 0s follow these instruction? > With enough layers of encoding and abstraction, sure!

Page 8: Computer Software & Software Development H&K Chapter 1

The Idea Behind Algorithms

Once an algorithm behind a task has been discovered

We don't need to understand the principles.

The task is reduced to following the instructions.

The intelligence is "encoded into the algorithm."

Page 9: Computer Software & Software Development H&K Chapter 1

Why bother writing an algorithm?

If we can specify an algorithm, we can automate the solution

A computing agent (human, robot, computer) can interpret and carry out the instructions to solve the problem

Page 10: Computer Software & Software Development H&K Chapter 1

Examples of Algorithms

Washing machine instructions

Instructions for baking a dish

Finding the greatest common divisor (GCD) of two numbers using Euclid’s algorithm

Page 11: Computer Software & Software Development H&K Chapter 1

Washing Machine InstructionsSeparate clothes into white clothes and

colored clothes.For white clothes:

Set water temperature knob to HOT.Place white laundry in tub.

For colored clothes:Set water temperature knob to COLD.Place colored laundry in tub.

Add 1 cup of powdered laundry detergent to tub.

Close lid and press the start button.

Page 12: Computer Software & Software Development H&K Chapter 1

Observations About the Washing Machine Instructions There are a finite number of well-ordered steps.

Each of the instructions are executable: we are capable of doing each of them.

At certain level of understanding, each of the instructions are unambiguous.

When we have followed all of the steps, the washing machine will wash the clothes and then will stop. So that we’ll observe the result in finite amount of time.

Page 13: Computer Software & Software Development H&K Chapter 1

Formal Definition of Algorithm

An algorithm is a A well ordered collection. . .Of unambiguous (clear) and effectively

computable operations. . .That produces a result. . .And halts in a finite amount of time.

Page 14: Computer Software & Software Development H&K Chapter 1

Algorithm RepresentationSyntax and Semantics

Syntax refers to the representation itself.Semantics refers to the concept represented

(i.e., the logic).In the English language, we have both

syntax and semantics.Syntax is the grammar of the language,

semantics is the meaning.Same applies to all languages.

Page 15: Computer Software & Software Development H&K Chapter 1

How are Algorithms Put Together?

Sequential instructionsdo them in the order given

Conditional instructionsdo them if a condition is true

Iterative instructionsdo them while a condition is true

C. Hundhausen, A. O’Fallon

Page 16: Computer Software & Software Development H&K Chapter 1

Sequential instructionsA series of steps or statements that are

executed in the order they are written.

Example:

Display “Enter two numbers: “Get number1Get number2sum = number1 + number2Display “sum = “, sum

Page 17: Computer Software & Software Development H&K Chapter 1

Conditional instructionsDefines one or more courses of action

depending on the evaluation of a condition.

Synonyms: selection, branching, decision

Examples: If (condition is true) If (condition is true) do this do this Else do that

Page 18: Computer Software & Software Development H&K Chapter 1

Iterative instructions

Allows one or more statements to be repeated as long as a given condition is true.

Synonyms: looping, repetitionExample:

While (condition is true) do this

Notice the repetition structure in Euclid’s Algorithm

Page 19: Computer Software & Software Development H&K Chapter 1

Can Algorithms Solve All Problems? Some problems are unsolvable

No algorithmic solution exists

Some problems have no tractable solution, meaning no solution can be found in a reasonable amount of time “Brute-force” algorithms

We simply don’t know an algorithm that will solve some problems Many “artificial intelligence” problems rely on heuristic search

C. Hundhausen, A. O’Fallon

Page 20: Computer Software & Software Development H&K Chapter 1

Formal Definition of Computer ScienceComputer science is the study of algorithms

including their formal and mathematical properties their hardware realizations their linguistic realizations their applications

It spans theory and practiceIt requires thinking in abstract and concrete

terms

C. Hundhausen, A. O’Fallon

Page 21: Computer Software & Software Development H&K Chapter 1

High-Level Programming Languages (1)High-level programming languages

The continuum of languages:

Low-level languages were created from the perspective of the machine

High-level languages, in contrast, are geared toward human programmers

C. Hundhausen, A. O’Fallon

Page 22: Computer Software & Software Development H&K Chapter 1

22

High-Level Programming Languages (2)Problem: Computers can’t understand

high-level programming languages

Solution: They must be translatedProgrammer uses a text editor to write a text-

based source file in a programming languageCompiler translates source file

Checks to make sure that program is syntactically correct

If so, the compiler translates the program into an object file with machine language instructions

C. Hundhausen, A. O’Fallon

Page 23: Computer Software & Software Development H&K Chapter 1

23

High-Level Programming Languages (3)Object file translated by compiler will not

execute! High-level programs often make use of software

libraries containing predefined pieces of code, including

Math functions Input/output functions

In order to execute, object file must be linked to object files containing these predefined pieces of code

A Linker program performs this operation A Loader program loads the linked program into

memory so that it can be executed

C. Hundhausen, A. O’Fallon

Page 24: Computer Software & Software Development H&K Chapter 1

Figure 1.11 of H&K: Entering, Translating, and Running a High-Level Language Program

Page 25: Computer Software & Software Development H&K Chapter 1

25

High-Level Programming Languages (4)Executing Programs

In this class, programs will execute in a text-based window called a console

Input data can be entered at command-line prompts

Output results will be displayed in the console window

In the real world, most programs have a graphical user interface

GUI programming is, however, beyond the scope of this course

C. Hundhausen, A. O’Fallon

Page 26: Computer Software & Software Development H&K Chapter 1

26

High-Level Programming Languages (5)Integrated Development Environments (IDE)

Combine compiler, linker, and loader with a source code editor

Insulate programmers from the details of compiling, linking, and loading

Provide a variety of tools to assist programmers, for example,

Source code syntax highlighting Auto-completion lists ("Intellisense") A debugger, which allows a programmer to step through

programs, one instruction at a timeC. Hundhausen, A.

O’Fallon