Algorithm vs Programming
Algorithm vs Programming
PROGRAM
1. AN ALGORITHM IS AN ABSTRACT CONCEPT.
WHEREAS, A PROGRAM IS A CONCRETE
IMPLEMENTATION OF THE ALGORITHM.
Algorithm Program
1. Start
2. Initialize a variable ‘result’ to 1.
3. Read the input number ‘n’.
4. Repeat the following until ‘n’ becomes 0:
a) Multiply ‘result’ by ‘n’
b) Decrement ‘n’ by 1.
5. Print the value of ‘result’ as the factorial.
6. Stop.
2. AN ALGORITHM CAN BE WRITTEN IN ANY
LANGUAGE, WHILE A PROGRAM MUST BE WRITTEN
USING A PROGRAMMING LANGUAGE ONLY.
Algorithm Program
1. Start
2. Initialize a variable ‘result’ to 1.
3. Read the input number ‘n’.
Program
4. Repeat the following until ‘n’ becomes 0:
a) Multiply ‘result’ by ‘n’
b) Decrement ‘n’ by 1.
5. Print the value of ‘result’ as the factorial.
6. Stop.
3. AN ALGORITHM IS DEVELOPED DURING THE
DESIGN PHASE, AND A PROGRAM IS DEVELPED
DURING THE DEVELOPMENT PHASE.
4. AN ALGORITHM DOES NOT DEPEND ON THE
HARDWARE AND OPERATING SYSTEM WHILE A
PROGRAM DEPENDS UPON THEM.
5. AN ALGORITHM IS ALWAYS ANALYZED,
WHILE A PROGRAM IS TESTED.
SUMMARY
PROGRAM
ALGORITHM
1. It is a concrete implementation.
1. It is an abstract concept.
2. Can be written using a programming
2. Can be written in any language.
language.
3. Developed during design phase.
3. Developed during development phase.
4. Independent of the hardware and
4. Depends on the hardware and operating
operating system.
system.
5. It is analyzed.
5. It is tested.
CHARACTERISTICS OF
AN ALGORITHM
CHARACTERISTICS OF AN ALGORITHM
1. Start. 1. Start.
2. Generate a random number. 2. Input the first number (let’s call it num1)
3. Output the random number. 3. Input the second number (let’s call it
4. Stop num2)
4. Add num1 and num2
5. Output the result of the addition.
6. Stop.
CHARACTERISTICS OF AN ALGORITHM
1. Start. 1. Start.
2. Generate a random number. 2. Input a number (let’s call it num).
3. Output the random number. 3. Calculate the square of num (let’s call it
4. Stop SquareResult).
4. Calculate the cube of num (let’s call it
CubeResult).
5. Output SquareResult.
6. Output CubeResult.
7. Stop.
CHARACTERISTICS OF AN ALGORITHM
1. Start. 1. Start.
2. Initialize count to 0. 2. Initialize count to 0,
3. Enter the loop. 3. Set a limit for the number of counts (let’s
4. Within the loop, increment the count say it is 10).
by 1. 4. Enter the loop that iterates up to the
5. Repeat steps 3 and 4. specified limit.
6. Stop. 5. Within the loop, increment the count by 1.
6. Repeat steps 4 and 5 until the specified
limit is reached.
7. Stop.
CHARACTERISTICS OF AN ALGORITHM
1. Start. 1. Start.
2. Input two numbers a and b. 2. Input two numbers a and b.
3. Perform some operation on a and b. 3. Calculate the sum of a and b and store it
4. Output the result. in the variable sum.
5. Stop. 4. Output the value of sum.
5. Stop.
CHARACTERISTICS OF AN ALGORITHM
1. Start. 1. Start.
2. Input a positive integer n. 2. Input a positive integer n.
3. Initialize the variable sum to 0. 3. Calculate the sum using the formula
4. Enter the loop that iterates from 1 to
n. 4. Out the value of sum.
5. Add the current iteration value to sum. 5. Stop.
6. Repeat steps 4 and 5.
7. Output the value of sum.
8. Stop.
SUMMARY OF CHARACTERISTICS OF AN
ALGORITHM
1. 0 or more Input
2. At least one Output
3. Finiteness
4. Definiteness
5. Effectiveness
Determine what characteristic(s) is/are
missing in the following algorithm:
1.Start.
2.Ask the user to input two numbers.
3.Check if both inputs are valid numeric values.
4.If valid, perform some operation of your
choice on two numbers.
5.Stop.