Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2 views

Algorithms 2

The document outlines the concept of algorithms, defining them as finite sequences of instructions to solve problems, and lists their essential characteristics such as input, output, finiteness, definiteness, and effectiveness. It also introduces pseudocode as a human-readable representation of algorithms and discusses flowcharts as a visual method to represent algorithms. Examples are provided for creating algorithms, pseudocode, and flowcharts for various problems.

Uploaded by

Aditya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Algorithms 2

The document outlines the concept of algorithms, defining them as finite sequences of instructions to solve problems, and lists their essential characteristics such as input, output, finiteness, definiteness, and effectiveness. It also introduces pseudocode as a human-readable representation of algorithms and discusses flowcharts as a visual method to represent algorithms. Examples are provided for creating algorithms, pseudocode, and flowcharts for various problems.

Uploaded by

Aditya Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Unit 2

PROGRAMMING ALGORITHMS
The algorithm
•An algorithm is a finite sequence of instructions which can be carried out to solve a
particular problem in order to obtain the desired results.
 A finite sequence of instructions
 The program must be planned before writing.
 Represents the logic of the program
 Instructions are to be written in the proper sequence.
 Expressed in the programming language, becomes the program
1. Characteristics of an algorithm
•An algorithm must satisfy the following criteria:
1)Input: Zero or more quantities are externally supplied as inputs.
2)Output: At least one quantity as output is produced.
3)Finiteness: An algorithm terminates after a finite number of steps.
4)Definiteness: Each instruction must be clear and unambiguous.
5)Effectiveness: Every instruction must be very basic so that it can b carried out in
principle, by a person using just a pencil and paper.
• Let us consider few example of creating algorithm for a given problem.
Examples
•Example 1: Algorithm for sum of two
numbers Step 1: Take the first number
from the user (input).
•Step 2: Take the second number from the
user (input). Step 3: Add the two numbers to
get the sum (process). Step 4: Display the
sum on the screen (output).
Example 2:
•Write an algorithm to check whether the entered number is
positive, negative or zero.
Step 1: Take the number from the user
Step 2: If the number is less than 0,
then display the entered number is negative.
Step 3: If the number is greater than 0,
display the entered number is positive.

Step 4: otherwise display the entered number is zero.


Example 3
calculating the sum of 10 numbers

Step 1: Let the sum be initially set to 0. Step 2: Let i be initially 1.

Step 3: Take the i th


number from the user. Step 4: Add i th
number to the
sum.
Step 5: Increase the value of i by 1.
Step 6: Check if the value of i is less than 10; then go to step 4.
Otherwise go to step 7.
Step 7: Output the sum
PSEUDODE
• A Pseudocode is defined as a step-by-step description of an algorithm.
Pseudocode does not use any programming language in its
representation instead it uses the simple English language text and
well known symbolic notations (or mathematical symbols)as it is
intended for human understanding rather than machine reading.
Pseudocode is the intermediate state between an idea and its
implementation(code) in a high-level language.
Example 2: Find whether given
year is a leap year or not.
Example 1: Pseudocde for sum of two numbers
Example 3: Take a number as
input and print the
multiplication table for it
Flow charts
•A flowchart is a pictorial representation of an algorithm. Flow chart consists of set of
flow chart symbols connected by arrows. Each symbol has its own meaning, tells to
compiler what must be done at that point. The sequence of flow chart symbols can be
considered as a program.
•Flow charts are better way of communicating logic of system. Problem can be analyzed in
effective way with the flowchart. If the algorithms are represented in a graphical or
pictorial form they are easy to understand. Efficient coding acts as Guide or Blue print
during system analysis or development phase.

1. Guidelines for flowchart


•Usually flow charts are drawn using some standard symbols. Some special symbols can
also be developed when required. Standard symbols, which are frequently required for
Example 1: Flow chart to find the sum of first 50
natural numbers
EXAMPLE 2:calculate the area of
circle.
EXAMPLE 3
Example using Algorithm and Flow
chart.
• Write an algorithm and draw a flowchart for computing
factorial n (n!) Where n! = 1 x 2 x 3 x …… x n
Flowchart
Practice questions
• Write Algorithm and pseudocode for the following. Draw flowchart
also.
1. To find the greatest from 2 numbers.
2. To print the Even numbers between 9 and 100.
3. To calculate the average from 25 exam scores.
4. To check a given number is prime or not.

You might also like