Algorithm Development

AliRaza2137 1,522 views 18 slides Mar 24, 2019
Slide 1
Slide 1 of 18
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18

About This Presentation

Algorithm Development
Algorithm Development
Algorithm Development


Slide Content

Algorithm Development

Algorithm is the sequence of steps to be performed in order to solve a problem by the computer.

Properties of Algorithm The given problem should be broken down into simple and meaningful steps. The step should be numbered sequentially. The steps should be descriptive and written in simple English.

Advantages of Algorithms Reduce Complexity by dividing the program into simple and meaningful parts. Increase Flexibility Algorithm is written so that the code may be written in any language. Ease of Understanding No need to understand a particular programming language to understand an algorithm.

How to write? Pseudocode is an artificial and informal language that helps programmers to develop algorithms. Pseudocode is very similar to everyday English. Two Steps to write an algorithm:- First produce a general algorithm (one can use pseudocode ) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language.

Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

Example Pseudocode : Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print “FAIL” else Print “PASS”

Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif

Write an algorithm to convert the length in feet to centimeter.

Pseudocode : Input the length in feet ( Lft ) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)

Algorithm Step 1: Input Lft Step 2: Lcm  Lft x 30 Step 3: Print Lcm

Write an algorithm that will calculate the roots of a quadratic equation Hint: d = sqrt ( ), and the roots are: x 1 = (– b + d )/2 a and x 2 = (– b – d )/2 a

Pseudocode : Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x 1 Calculate x2 Print x 1 and x2

Algorithm : Step 1: Input a, b, c Step 2: d  sqrt ( ) Step 3: x 1  (– b + d ) / (2 x a ) Step 4: x 2  (– b – d ) / (2 x a ) Step 5: Print x 1, x 2

Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM Step 1: Input VALUE1, VALUE2 Step 2: if ( VALUE1 > VALUE2) then MAX  VALUE1 else MAX  VALUE2 endif Step 3: Print “The largest value is”, MAX

Write an algorithm that reads three numbers and prints the value of the largest number . Step 1: Input N1, N2, N3 Step 2: if ( N1>N2) then if ( N1>N3) then MAX  N1 [N1>N2, N1>N3] else MAX  N3 [N3>N1>N2] endif else if ( N2>N3) then MAX  N2 [N2>N1, N2>N3] else MAX  N3 [N3>N2>N1] endif endif Step 3: Print “The largest number is”, MAX

Example Bonus Schedule OVERTIME – (2/3)*ABSENT Bonus Paid >40 hours >30 but  40 hours >20 but  30 hours >10 but  20 hours  10 hours $50 $40 $30 $20 $10

Step 1: Input NAME,OVERTIME,ABSENT Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then PAYMENT  50 else if ( OVERTIME–(2/3)*ABSENT > 30) then PAYMENT  40 else if ( OVERTIME–(2/3)*ABSENT > 20) then PAYMENT  30 else if ( OVERTIME–(2/3)*ABSENT > 10) then PAYMENT  20 else PAYMENT  10 endif Step 3: Print “Bonus for”, NAME “is $”, PAYMENT
Tags