Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Computer Programming

Similar presentations


Presentation on theme: "Introduction to Computer Programming"— Presentation transcript:

1 Introduction to Computer Programming
Lesson 2

2 How People Solve Problems
A Problem exists when what we have (Data) is not the same as what we want (information) People create a solution (called an Algorithm) which manipulates Data into Information People do this quickly and often in a complex way

3 How Computers Solve Problems
Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step at a time Complex “Human” Algorithms must be broken down into simple step-by-step instructions BEFORE they can be translated into computer code

4 Algorithms (source : wikipedia)
In mathematics, computing, linguistics and related disciplines, an algorithm is a procedure (a finite set of well-defined instructions) for accomplishing some task which, given an initial state, will terminatee in a defined end-state. Algorithms are essential to the way computers process information, because a computer program is essentially an algorithm that tells the computer what specific steps to perform (in what specific order) in order to carry out a specified task, such as calculating employees’ paychecks or printing students’ report cards. Thus, an algorithm can be considered to be any sequence of operations which can be performed by a Turing-Complete system.

5 Problem Solving Problem Solving is the ability to understand what you have, what you want, and creating a set of instructions to change what you have into what you want Good Problem Solving Skills are based on knowledge, experience and logic Good Programmers NEVER make assumptions

6 Expressing the Algorithms
A “Standard” way of describing an algorithm must exist if we expect our solution to be understood by others easily There are two standards in programming: NATURAL LANGUAGE PSEUDOCODE FLOWCHARTS PROGRAMMING LANGUAGE

7 Expressing The Algorithms
Algorithms can be expressed in many kinds of notation, including natural languages, pseudocode, flowcharts, and programming languages. Natural language expressions of algorithms tend to be verbose and ambiguous, and are rarely used for complex or technical algorithms. Pseudocode and flowcharts are structured ways to express algorithms that avoid many of the ambiguities common in natural language statements, while remaining independent of a particular implementation language. Programming languages are primarily intended for expressing algorithms in a form that can be executed by a complete, but are often used as a way to define or document algorithms.

8 Natural Language "...prose to describe an algorithm, ignoring the implementation details. At this level we do not need to mention how the machine manages its tape or head“ In the philosophy of language, a natural language (or ordinary language) is a language that is spoken, written, or signed (visually or tactilely) by humans for general-purpose communication, as distinguished from such constructs as computer-programming languages or the "languages" used in the study of formal logic, especially mathematical logic.

9 Pseudo Code “Pseudo” means “pretend” or “false”
Pseudo Code is pretend or false computer code; generic English-like terms that are somewhat like computer code Pseudo Code is not as standardized as flowcharts, and does not facilitate the breaking down of problems as well as a flowchart does

10 Pseudocode (wikipedia)
Pseudocode (derived from pseudo and code) is a compact and informal high-level description of a computer programming algorithm that uses the structural conventions of programming languages, but omits detailed subroutines, variable declarations or language-specific syntax. The programming language is augmented with natural language descriptions of the details, where convenient.

11 Flowcharts A Flowchart is a Visual Representation of an algorithm
A Flowchart uses easy-to-understand symbols to represent actions on data and the flow of data Flowcharts aid in breaking down a problem into simple steps

12 Selection Selection is the decision-making construct
It is used to make yes/no or true/false decisions logically Selection can be thought of as “if something is true take this action, otherwise take that action”

13 The Three Computer Programming Constructs
Any problem, regardless of how complex, can be broken down into three basic CONSTRUCTS SEQUENCE SELECTION ITERATION

14 Sequence Sequence is the most basic of the constructs
It is simply performing one step after another Each step is followed in a specific sequence, hence the name Sequence can be thought of as “do this, then do this, then do this”

15 Iteration Iteration comes from the word “reiterate”, which means to repeat Iteration is a looping construct Iteration is a combination of decision and sequence and can repeat steps Iteration can be thought of as “while something is true, do this, otherwise stop”

16 Visualizing The Constructs
By using Flowchart symbols, we can visualize the three basic computer constructs Every algorithm ever created is made up of only these three constructs

17 Basic Flowchart Symbols
Process Input/Output Terminator Decision Connector Data Flow

18 The Basic Flowchart Symbols
The terminator shows where a specific piece of an algorithm beings and ends A process is a basic action or actions on data A decision is a logical test with two possible data paths resulting from one

19 The Basic Flowchart Symbols
Input/Output gets data or displays information to the user of the algorithm A connector connects two or more data flows into one A data flow shows the direction of data’s movement through the algorithm

20 Sequence

21 Selection F T

22 Iteration F T

23 Example : You have problem when staying at home. Your lamp doesn’t work and you need the light. Express the algorithm to solve the problems !

24 Algorithms : Lamp doesn’t work Is lamp plugged in ? If No plug in lamp and finish If yes, Check the bulb if it is burned out ? If yes replace bulb Buy new lamp

25 Example : One of the simplest algorithms is to find the largest number in an (unsorted) list of numbers. The solution necessarily requires looking at every number in the list, but only once at each. From this follows a simple algorithm, which can be stated in a high-level description English prose, as:

26 Natural language: Assume the first item is largest. Look at each of the remaining items in the list and if it is larger than the largest item so far, make a note of it. The last noted item is the largest in the list when the process is complete.

27 (Quasi-) Formal description:
Written in prose but much closer to the high-level language of a computer program, the following is the more formal coding of the algorithm in pseudo code : Algorithm LargestNumber Input: A non-empty list of numbers L. Output: The largest number in the list L. largest ← L0 for each item in the list L≥1, do if the item > largest, then largest ← the item return largest "←" is a loose shorthand for "changes to". For instance, "largest ← item" means that the value of largest changes to the value of item. "return" terminates the algorithm and outputs the value that follows.

28 Make the Flowchart for the example above !!!

29 Assignment ! Make an algorithms in high level language, pseudo code and flowchart for Computing factorial N (N!) ! Finding roots of aX2 + bX + c = 0 Bisection Method to find a root of the equation.

30


Download ppt "Introduction to Computer Programming"

Similar presentations


Ads by Google