1 / 27

Computer Software & Software Development H&K Chapter 1

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.

glenys
Download Presentation

Computer Software & Software Development H&K Chapter 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer Software & Software DevelopmentH&K Chapter 1 Instructor – GokcenCilingir Cpt S 121 (June 20, 2011) Washington State University

  2. 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

  3. 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

  4. 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

  5. Euclid’s Algorithm Problem: Find the largest positive integer that divides the given two positive integers evenly(i.e., the greatest common divisor). Algorithm: • Assign M and N the values of the larger and smaller of the two positive integers, respectively. • Divide M by N and call the remainder R. • 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.

  6. 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.

  7. 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!

  8. 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."

  9. 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

  10. Examples of Algorithms • Washing machine instructions • Instructions for baking a dish • Finding the greatest common divisor (GCD) of two numbers using Euclid’s algorithm

  11. Washing Machine Instructions • Separate 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.

  12. 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 resultin finite amount of time.

  13. 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.

  14. Algorithm Representation • Syntax 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.

  15. How are Algorithms Put Together? • Sequential instructions • do them in the order given • Conditional instructions • do them if a condition is true • Iterative instructions • do them while a condition is true

  16. Sequential instructions • A series of steps or statements that are executed in the order they are written. • Example: Display “Enter two numbers: “ Get number1 Get number2 sum= number1+ number2 Display “sum = “, sum

  17. Conditional instructions • Defines 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

  18. Iterative instructions • Allows one or more statements to be repeated as long as a given condition is true. • Synonyms: looping, repetition • Example: While (condition is true) do this • Notice the repetition structure in Euclid’s Algorithm

  19. 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

  20. Formal Definition of Computer Science • Computer science is the study of algorithms including • their formal and mathematical properties • their hardware realizations • their linguistic realizations • their applications • It spans theory and practice • It requires thinking in abstract and concrete terms

  21. 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

  22. High-Level Programming Languages (2) • Problem: Computers can’t understand high-level programming languages • Solution: They must be translated • Programmer uses a text editor to write a text-based source file in a programming language • Compiler 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

  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

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

  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

  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 time

  27. References • J.R. Hanly & E.B. Koffman, Problem Solving and Program Design in C (6th Ed.), Addison-Wesley, 2010 • http://www.cs.umbc.edu/courses/104/fall05/ordonez/powerpoint/ • http://www.eecs.wsu.edu/~aofallon/cpts121/

More Related