1 Algorithm…. 2 Algorithm: Is a planned set of steps to solve certain problem Ex.: Assume for instance that the gross pay of an employee is to be calculated.

Slides:



Advertisements
Similar presentations
Solving IPs – Cutting Plane Algorithm General Idea: Begin by solving the LP relaxation of the IP problem. If the LP relaxation results in an integer solution,
Advertisements

CS107 Introduction to Computer Science Lecture 2.
PROBLEM SOLVING TECHNIQUES
Static Single Assignment CS 540. Spring Efficient Representations for Reachability Efficiency is measured in terms of the size of the representation.
1 Flowchart. 2 Flowchart: It is a diagram consists of symbolic block that represents the algorithm step by step Symbols of flowchart: 1. Terminal (start,
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Fundamentals of Algorithms MCS - 2 Lecture # 4
Tutorial #6 PseudoCode (reprise)
1 Pseudocode For Program Design. 22 Rules for Pseudocode Write only one statement per line Capitalise initial keyword Indent to show hierarchy and structures.
CONTROL STRUCTURES: SEQUENTIAL, SELECTIVE, AND REPETITIVE
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
CS107 Introduction to Computer Science Lecture 2.
Designing Algorithms Csci 107 Lecture 3. Designing algorithms Last time –Pseudocode –Algorithm: computing the sum 1+2+…+n –Gauss formula for 1+2+…+n Today.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
Review Algorithm Analysis Problem Solving Space Complexity
ALGORITHMS AND FLOWCHARTS
Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 5 Structured Program.
Sales and Income Tax. Sales tax – a tax that is added to the cost of goods or services based on the percentage of the cost. Income tax – A tax that is.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
An ordered sequence of unambiguous and well-defined instructions that performs some task and halts in finite time Let's examine the four parts of this.
Looping While-continue.
Algorithms In general algorithms is a name given to a defined set of steps used to complete a task. For example to make a cup of tea you would fill the.
Java Keywords  Reserved Words Part of the Java language Examples: public, static, void  Pre-defined Java Identifiers Defined in Java Libraries Examples:
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Instructor Information: Dr. Radwa El Shawi Room: Week # 1: Overview & Review.
DATA STRUCTURES (CS212D) Week # 1: Overview & Review.
Software Life Cycle What Requirements Gathering, Problem definition
ANALYSIS AND ALGORITHM DESIGN - IV. Repeat statements/looping/counting/iterations It is often necessary to repeat certain parts of a program a number.
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Basic Control Structures
Bell Quiz. Objectives Solve problems involving percents. Write proportion and percent statements.
Pseudocode An Introduction. Flowcharts were the first design tool to be widely used, but unfortunately they do not reflect some of the concepts of structured.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Data Structures & Algorithms CHAPTER 1 Introduction Ms. Manal Al-Asmari.
Topic: Control Statements. Recap of Sequence Control Structure Write a program that accepts the basic salary and allowance amount for an employee and.
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Pseudocode Skill Area Materials Prepared by Dhimas Ruswanto, BMm.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
CS 101 – Oct. 7 Solving simple problems: create algorithm Structure of solution –Sequence of steps (1,2,3….) –Sometimes we need to make a choice –Sometimes.
Introduction to Flowcharts
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Lecture 2. Algorithms and Algorithm Convention 1.
ALGORITHMS AND FLOWCHARTS
Lesson 2 Flowcharting.
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
Topic:- ALGORITHM Incharge Faculty – Lokesh Sir.
PROGRAM CONTROL STRUCTURE
Algorithms and Flowcharts
Pseudocode Upsorn Praphamontripong CS 1110 Introduction to Programming
ALGORITHMS & FLOWCHARTING II
ALGORITHMS AND FLOWCHARTS
Control Structure Senior Lecturer
ALGORITHMS AND FLOWCHARTS
How to develop a program?
Algorithms & Pseudocode
Algorithm Discovery and Design
ALGORITHMS AND FLOWCHARTS
Computer Programming.
Week # 1: Overview & Review
Computer Science 2 Hashing.
Flowchart.
Calculate 81 ÷ 3 = 27 3 x 3 x 3 3 x 3 x 3 x 3 ÷ 3 = This could be written as
Presentation transcript:

1 Algorithm…

2 Algorithm: Is a planned set of steps to solve certain problem Ex.: Assume for instance that the gross pay of an employee is to be calculated and then 10 percent of the gross is to remove as tax. The yield being the net pay. Write down the algorithm for this problem. Sol.: 1. Begin 2. input name, hours_worked, and wage par hour 3. calculate gross_pay = hours_worked * wage par hour 4. calculate tax = (10/100) * gross_pay 5. calculate net_pay = gross_pay – tax 6. print name, net_pay 7. End

3 Algorithm: Ex.: Write an algorithm to read the name and the mark (one) for one student then add to his mark 5 marks Sol.: 1. Begin 2. input name, mark 3. new_mark = mark+5 4. print name, new_mark 5. End

4 Algorithm: Ex.: Write an algorithm to read the name and mark of student and calculate the new mark of each by adding 5 to its mark. We have 10 students Sol.: 1. Begin 2. studentcount =1 3. if studentcount > 10 then Stop else A. read name, mark B. calculate new_mark = mark + 5 C. print name, new_mark D. studentcount = studentcount +1 E. goto step 3

5 Pseudo code algorithm: It is an algorithm written in a language that is very close to high level languages while …do loop syntax: while ( condition) do begin end ex.: 1. start 2. student_count = 1 3. while (student_count < = 10) do 4. begin 5. read name, mark 6. new_mark = mark print name, new_mark 8. student_count = student_count end 10. stop

6 Pseudo code algorithm: repeat … until loop syntax: repeat until (condition); ex.: 1. start 2. student_count = 1 3. repeat 4. read name, mark 5. new_mark = mark print name, new_mark 7. student_count = student_count until (student_count > 10); 9. stop

7 Pseudo code algorithm: For loop syntax: for variable_name = initial_value to end_value do begin end ex.: 1. start 2. for student_count = 1 to 10 do 3. begin 4. read name, mark 5. new_mark = mark print name, new_mark 7. end 8. stop

8 Pseudo code algorithm: ex.: write an algorithm to compute the sum of n numbers sol.: 1. start 2. read n 3. sum = 0 4. for I = 1 to n 5. begin 6. sum = sum + I 7. end 8. write sum 9. stop

9 Pseudo code algorithm: ex.: write an algorithm to compute y= 1+ 22/2 + 33/3 + … + nn/n sol.: 1. start 2. read n 3. sum = 0 4. for I = 1 to n do 5. begin 6. sum = sum + (I ** I) / I 7. end 8. y = sum 9. print y 10. stop

10 Pseudo code algorithm: if statement: syntax: if ( condition) then begin end or: if ( condition) then begin end else begin end or: if ( condition) then begin end else if ( condition) then begin end or: if ( condition) then else

11 Pseudo code algorithm: Ex.: Write an algorithm to find the maximum of two values Sol.: 1. Start 2. Read a, b 3. if ( a>b) then 4. max = a 5. else 6. if ( b>a) then 7. max = b 8. else 9. print (a = b) 10. print max 11. Stop

12 Pseudo code algorithm: Ex.: Write an algorithm to find the maximum of three values Sol.: 1. Start 2. Read a, b, c 3. if ( a>b) then 4. if ( a>c) then 5. max = a 6. else 7. if ( b>c) then 8. max = b 9. else 10. max = c 11. else 12. if ( b>c) then 13. max = b 14. else 15. max = c 16. print max 17. Stop

13 Pseudo code algorithm: ex.: write an algorithm to compute y= 1- 22/2 + 33/3 - … nn/n sol.: 1. start 2. read n 3. sum = 0 4. for I = 1 to n do 5. begin 6. if ( I mod 2 = 0) then 7. sum = sum - (I ** I) / I 8. else 9. sum = sum + (I ** I) / I 10. end 11. y = sum 12. print y 13. stop