Introduction to Computer Programming

Slides:



Advertisements
Similar presentations
Algorithms An algorithm is a finite sequence of instructions, logic, an explicit step-by-step procedure for solving a problem. Specific algorithms sometimes.
Advertisements

CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
How Are Algorithms Developed?
Reference :Understanding Computers
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
ITEC113 Algorithms and Programming Techniques
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Problem Solving Chapter 2. What is an algorithm? n A solution to a problem that is: –Precise –Effective –Terminating.
The Program Design Phases
Review Algorithm Analysis Problem Solving Space Complexity
Fundamentals of C programming
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
ALGORITHM List of instructions for carrying out some process step by step. A sequence of instructions which has a clear meaning and can performed with.
Algorithm Design.
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
FUNDAMENTALS OF ALGORITHMS MCS - 2 LECTURE # 2. MODEL OF COMPUTATION REPRESENTATION OF ALGORITHMS.
Algorithm Discovery and Design Objectives: Interpret pseudocode Write pseudocode, using the three types of operations: * sequential (steps in order written)
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
How Computers Solve Problems Computers also use Algorithms to solve problems, and change data into information Computers can only perform one simple step.
 Problem Analysis  Coding  Debugging  Testing.
Algorithms and Flowcharts
Pseudocode (pronounced SOO-doh-kohd)  is a detailed yet readable description of what a computer program or algorithm must do, expressed in a formally-styled.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Learning outcomes 5 Developing Code – Using Flowcharts
ALGORITHMS AND FLOWCHARTS
Algorithms and Problem Solving
GC101 Introduction to computers and programs
Introduction to Programming / chapter 3 / COM1022
INTRODUCTION TO PROBLEM SOLVING
Programming Languages
REPETITION CONTROL STRUCTURE
GC211Data Structure Lecture2 Sara Alhajjam.
Chapter 2- Visual Basic Schneider
ALGORITHMS AND FLOWCHARTS
Lecture 3 of Computer Science II
Algorithm and Ambiguity
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
Lecture 2 Introduction to Programming
Introduction To Flowcharting
Algorithm and Ambiguity
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
PROBLEM SOLVING SKILLS
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Design and Implementation
Introduction to Algorithms and Programming
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
Algorithm and Ambiguity
How Are Algorithms Developed?
Algorithms and Problem Solving
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
ICT Gaming Lesson 2.
Introduction to Programming
Basic Concepts of Algorithm
WRITING AN ALGORITHM, PSEUDOCODE, AND FLOWCHART LESSON 2.
Presentation transcript:

Introduction to Computer Programming Lesson 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

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

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.

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

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

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.

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.

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

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.

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

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”

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

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”

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”

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

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

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

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

Sequence

Selection F T

Iteration F T

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 !

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

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:

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.

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

Make the Flowchart for the example above !!!

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.