Download presentation

Presentation is loading. Please wait.

Published byClifford Carpenter Modified over 2 years ago

1
Algorithm –History Muhammad ibn Musa Al-Khwarizmi http:// www -groups.dcs.st-andrews.ac.uk/~history/Mathematicians/Al- Khwarizmi.html Book on arithmetic: Hindu numeration, decimal numbers, use of zero, method for finding square root Latin translation (c.1120 CE): “Algoritmi de numero Indorum” Book on algebra Hisab al-jabr w’al-muqabala

2
The Problem-solving Process Problem specification Algorithm Program Executable (solution) Analysis Design Implementation Compilation

3
Components of an Algorithm 1. Variables and values 2. Instructions a.Sequences b.Procedures c.Selections d.Repetitions 3. Also required: Documentation

4
Algorithm basics It is a step by step procedure to solve a given problem in/with finite number of steps, where every step is labeled with a step number and no 2 steps are same. The components of an algorithm comprises of simple English statements with mathematical expressions, that specify step by step procedure towards the problem solution

5
Algorithm basics Properties of an algorithm It should be definite- no ambiguity It should be finite- definite number of steps It should be complete- must work successfully for which it has been designed for. It should be efficient

6
Need for writing algorithm Effective communication-understandability Effective analysis-easy to write programs Proper documentation- to identify logical errors Easy and efficient coding Program debugging-detect & fix errors Program maintenance- maintenance of the software becomes easier

7
Algorithm -- Examples 1. Assembly instructions for a model 2. The rules of how to play a game 3. VCR instructions 4. Directions for driving from A to B

8
Algorithmic Notations Algorithms are identified by a algorithm name followed by the type of computation it performs Ex: Algorithm Area_of_Circle ( This algorithm computes the area of a circle given radius) Each step is identified by a number followed by a description of what it does Ex: Step 3:[write the area of the circle] print area Finally the algorithm is terminated by using a stop/end. Step 4: [Stop] finished Provide the necessary information as what the algorithm performs, along with the inputs and outputs

9
Algorithm Example #1: Algorithm Area_of_a Circle This algorithm computes the area of a circle given radius Step 1: [start] Step 2: [ input the value of radius] read radius Step 3: [ calculate the area of the circle] area= 22/7*r*r Step 4: [ output the calculated area] write area Step 5: [finished] stop

10
Algorithm Example #2: Algorithm Area_of_a_Rectangle This algorithm computes the area of a rectangle given length and breadth step 1: [start] Step 2: [ input the value of length and breadth] read length, breadth Step 3: [ calculate the area of the rectangle] area= length * breadth Step 4: [ output the calculated area] write area Step 5: [finished] stop

11
Exchange (Swap) the contents of 2 variables ab temp 13 2

12
Concept of Swapping “SWAP”- refers to exchange the values between 2 variables, if the 2 variables are taken as a & b with initial values a=2, b=3 then before swapping a=2,b=3, but after swapping a=3,b=2, indicating that the values are interchanged & this is achieved by using a temporary variable called “temp” to hold the value during the exchange process. Steps involved in the exchange process are 1. temp=a, 2. a=b, 3. b=temp. Copy the value of a to temp Copy the value of b to a Copy the value of temp to b

13
Algorithm Example # 3: Algorithm Swap This algorithm exchanges the values of a with b and vice versa step 1: [start] Step 2: [ input the value of a and b] read a, b Step 3: [ perform the exchange operation] temp=a, the value of a is put to temp, hence a is empty a=b, the value of b is put to a, thus b is empty b=temp, temp contains the value of a and is put to b Step 4: [ output the exchanged values of a and b] write a & b Step 5: [finished] stop

14
Algorithm Example # 4: Algorithm Area of Triangle This algorithm calculates the area of a triangle where 3 sides a, b,c, are given step 1: [start] Step 2: [ input the value of a,b, c] read a, b, c Step 3: [ calculate the value of S] s= (a+b+c)/2. Step 4: [ compute the area of the triangle] area=sx(s-a)x(s-b)x(s-c) Step 5: [ display the calculated area] write area Step 6: [finished] stop

15
Algorithm Example # 5: Algorithm Simple Interest This algorithm calculates the simple interest given principle, rate and time step 1: [start] Step 2: [ input the value of p,t, r] read p, t, r Step 3: [ calculate the value of Simple interest] S.I.= (p*t*r)/100. Step 4: [ display the calculated simple interest] write S.I. Step 5: [finished] stop

16
Decision making Decision making is an integral part of every one’s life, in contrast to the computer languages have ”language constructs”, by which decisions are made, 2-way decision making being the most general Example: given a number its type is determined depending upon it being greater or lesser than 0. For example in c programming language the construct if..else provides a 2 way decision making facility

17
Format of a if..else statement If (logical expression) { True block statements } Else { False block statements }

18
Algorithm Example # 6: Algorithm odd_Even This algorithm determines whether the given number is odd or even step 1: [start] Step 2: [ input the value of n] read n Step 3: [ determine whether the given number is odd or even] if(n/2=0) write n as even else write n as odd end if Step 4: [finished] stop

19
Algorithm Example # 7: Algorithm Pos Neg Zero This algorithm checks whether the given number is positive, negative or zero step 1: [start] Step 2: [ input the value of n] read n Step 3: [ determine whether the given number is positive, negative, zero] if(n>0) write n as positive go to step 4 else write n as negative go to step 4 endif write n as zero Step 4: [finished] stop

20
When a given problem is large it is always natural to divide it into smaller independent sub problems and then to solve these sub problems independently and to merge the results of all these sub problems together to get the final solution. A central program that “puts together”, the smaller sub programs are referred to as the main programs or main functions & this strategy is commonly referred to as the divide and conquer strategy. The subprograms are referred differently in the programming languages for example in PASCAL they are referred as PROCEDURES, in C as FUNCTIONS and in FORTRAN as SUBPROGRAMS etc.

21
From Algorithms to Programs Problem C Program Algorithm: A sequence of instructions describing how to do a task (or process)

Similar presentations

OK

| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.

| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Problem solution reading ppt on ipad Ppt on temples of india in hindi Ppt on varactor diode equation Ppt on breast cancer Ppt on personal financial planning Ppt on tcp/ip protocol suite solutions Ppt on tamper resistant Ppt on rf based 8 channel remote control Adrenal gland anatomy and physiology ppt on cells Ppt on regular expression builder