0% found this document useful (0 votes)
4 views12 pages

Algorithm Notes

The document provides an introduction to algorithms, detailing their characteristics, control structures, and examples of algorithms for various problems. It emphasizes the importance of algorithms in programming and outlines key concepts such as input, output, finiteness, definiteness, and effectiveness. Additionally, it includes examples of algorithms for tasks like adding numbers, checking for prime numbers, and finding the Fibonacci series.

Uploaded by

Bhaskar Naidu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Algorithm Notes

The document provides an introduction to algorithms, detailing their characteristics, control structures, and examples of algorithms for various problems. It emphasizes the importance of algorithms in programming and outlines key concepts such as input, output, finiteness, definiteness, and effectiveness. Additionally, it includes examples of algorithms for tasks like adding numbers, checking for prime numbers, and finding the Fibonacci series.

Uploaded by

Bhaskar Naidu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[Document title]

[Document subtitle]

[DATE]
[Company name]
[Company address]
VIJETHA DEGREE COLLEGE [Document title]

Bhaskar Naidu 1
VIJETHA DEGREE COLLEGE [Document title]

INTRODUCTION TO ALGORITHMS AND FLOWCHART


ALGORITHM AND ITS CHARACTERISTICS
Algorithm:
Algorithm is a step-by-step procedure, which defines a set of
instructions to be executed in certain order to get the desired
output. Algorithms tell the programmers how to code the program.
Algorithms are generally analyzed on two factors − time and space.
That is, how much execution time and how much extra space
required by the algorithm.
Characteristics of Algorithm:
Input − An algorithm should have 0 or more well-defined inputs.
Output − An algorithm should have 1 or more well-defined outputs,
and should match the desired output.
Finiteness − Algorithms must terminate after a finite (countable)
number of steps.
Definiteness / Unambiguous − Algorithm should be clear and
unambiguous. Each of its steps (or phases), and their inputs/outputs
should be clear and must lead to only one meaning.
Effectiveness- It is measured in terms of time and space.
WORD
Algorithm Notation
Name ofhghjgjgv
Jjgghv jjhg algorithm:
hvhh Specifies problem to be solved. That should be

ART
hvh hvh hvhv hvhvhhjdfhjsf
indjfdsf
capital letters.
sdjfsdf sdjfsd fsdjfds
Step no -dsjfds
fjdsf sdjfsdf Identification
fjsdf tag of an instruction and it is an unsigned
position number along with explanatory comment.
sdjfsd fdsjfds fjsdf dsjfsd
fdsjfsd fjsdf sdjff sdjfds fjsdf
Termination
sdjfsd fjdsf sdjfsd fdsjf
Control Structures
sdfjsdf sdjfds fjdsf dsfjds used in Algorithms:
An algorithm uses three control structures 1. Sequence 2.
Decision 3. Repetition
Sequence: Sequence means that each fdsjf stepsdfjsdfof
dsjf the
fjsdf algorithm is
executed in a specified order. sdjfds fsdjfsd fjsdf sdjfsd
fdsjfds fjfsdfjsdbfs
Example: This algorithm performs the steps dfjdsfdsbjfsdf in a purely sequential
order. sdfjsdfsdbjfsdf sdjfsfs
Problem − Design an algorithm to add two numbers and
dfjsdf sdjfbdsf

COMP
display the result.
Algorithm: ADD:
sdjfbbfsjdfsdn
fsdjfbdsjfbdsj dsjfb

UTER
Step 1 − START
Step 2 − Input the first number as A
Step 3 − Input the second number as B
Step 4 − Set C ← A + B
Step 5 – Display C
Step 6 – STOP

Bhaskar Naidu 2
VIJETHA DEGREE COLLEGE [Document title]

Decision: Decision statements are used when the execution of a


process depends on some condition. The general form of "if" is
if condition then if condition
then
Process OR
Process1
else

Process2
This form of decision is known as if - else construct. Here, If the
condition is true then process1 is executed else process2 is
executed.

Example Problem − Design an algorithm to add two numbers


and display the result.
Algorithm: EQUALITY_OF_2_NUMBERS:
Step 1 − START
Step 2 − Input the first number as A
Step 3 − Input the second number as B
Step 4 − if A = B then
Display "Equal"
else
Display "Not Equal"
Step 5 – STOP
Repetition: Repetition statements are used to execute one or more
steps for a number of times. Repetition can be implemented using 3
constructs, while, do-while and for loop. These loops execute one or
more steps until some condition is true.
Example Problem − Design an algorithm to print first 10
natural numbers
Algorithm: NATURAL_NUMBERS:
Step 1 − START
Step 2 − [Initialize] set I = 1, N = 10
Step 3 − Repeat steps 4 and 5 while I <= N
Step 4 − Print I
Step 5 – Set I = I + 1
Step 6 – STOP
Some example algorithms
Write an algorithm to find the largest among three different
numbers entered by user.
Step 1: Start
Step 2: Declare variables a, b and c.

Bhaskar Naidu 3
VIJETHA DEGREE COLLEGE [Document title]

Step 3: Read variables a, b and c.


Step 4: IF a > b THEN
IF a > c THEN
Display a is the largest number.
Else
Display c is the largest number.
Else
IF b > c THEN
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
Write an algorithm to find all roots of a quadratic equation
ax2+bx+c=0.
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminate
D ←b2-4ac
Step 4: If D≥0
r1← (-b+√D)/2a
r2← (-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp ←b/2a
ip ←√(-D)/2a
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
Write an algorithm to find the factorial of a number entered
by user.
Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
factorial←1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i=n
5.1: factorial ←factorial * i
5.2: i←i+1
Step 6: Display factorial
Step 7: Stop

Bhaskar Naidu 4
VIJETHA DEGREE COLLEGE [Document title]

Write an algorithm to check whether a number entered by


user is prime or not.
Step 1: Start
Step 2: Declare variables n, i, flag.
Step 3: Initialize variables
flag←1
i←2
Step 4: Read n from user.
Step 5: Repeat the steps until i<(n/2)
5.1 If remainder of n÷i equals 0
flag←0
Go to step 6
5.2 i←i+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop
Write an algorithm to find the Fibonacci series till term
≤1000.
Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term←0 second_term←1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term≤1000
5.1: temp←second_term
5.2: second_term←second_term+first term
5.3: first_term←temp
5.4: Display second_term
Step 6: Stop
Keywords used in Pseudo Code:
In Pseudo code for decision making and looping the designer must
use the keywords like If --- EndIf, Case --- EndCase, While --
EndWhile, Do While --- EndDo, Do Until --- EndDo, Call --- with
(Parameters), Call Return ---; Return, When and so on.
IF -- ENDIF: It is for execute a sequence based on a condition.
IF condition THEN IF age >= 18 THEN
Sequence 1; display Eligible to
vote
ELSE ELSE
Sequence 2; display Not Eligible
ENDIF ENDIF
Bhaskar Naidu 5
VIJETHA DEGREE COLLEGE [Document title]

WHILE: It specifies a loop that tests a condition at the top and


executes the sequence if the condition is true. After each iteration
the condition will be tested and the loop will be executed as long as
the condition is true.
WHILE condition WHILE I < 10
Sequence Print I
ENDWHILE Increment I
ENDWHILE
CASE: It is used to construct a multi way branch based on condition
that are mutually exclusive.
CASE expression OF CASE day OF
condition 1: sequence-1; 1: print "Sunday"
condition 2: sequence-2; 2: print "Monday"
. 3: print "Tuesday"
. 4: print "Wednesday"
condition n: sequence-n; 5: print "Thursday"
OTHERS: default: sequence; 6: print "Friday"
ENDCASE; 7: print "Saturday"
ENDCASE
REPEAT: This is similar to WHILE loop, except that the test condition
is performed at the end of loop.
REPEAT REPEAT
sequence print I
UNTIL condition Increment I
UNTIL I <= 10
FOR: It is used for iterating a sequence for a specific number of
times.
FOR iteration bounds FOR each student in the class
sequence Add 10 as bonus marks
ENDFOR ENDFOR

Bhaskar Naidu 6
VIJETHA DEGREE COLLEGE [Document title]

RollNo Name Sub1 Sub2


101 Sai 34 45
102 Laxman 67 78
103 Kamal 67 36

MAY
M T W T F S S
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

Enrollment in local colleges, 2005


College New students Graduating students Change
Undergraduate
Cedar University 110 103 +7

Elm College 223 214 +9

Maple Academy 197 120 +77

Pine College 134 121 +13

Oak Institute 202 210 -8

Graduate
Cedar University 24 20 +4

Elm College 43 53 -10

Maple Academy 3 11 -8

Pine College 9 4 +5

Oak Institute 53 52 +1

Total 998 908 90

Source: Fictitious data, for illustration purposes only


Enrollment in local colleges, 2005
College New students Graduating students Change
Undergraduate
Cedar University 110 103 +7

Elm College 223 214 +9

Maple Academy 197 120 +77

Pine College 134 121 +13

Oak Institute 202 210 -8

Bhaskar Naidu 7
VIJETHA DEGREE COLLEGE [Document title]

Graduate
Cedar University 24 20 +4

Elm College 43 53 -10

Maple Academy 3 11 -8

Pine College 9 4 +5

Oak Institute 53 52 +1

Total 998 908 90

Source: Fictitious data, for illustration purposes only

27-Nov-25

9:59:46 AM


27-11-2025 09:59

ENGINEERING
IT'S TIME TO
DEGREE
THINK
PHARMACY
DIET
Bhaskar Naidu 8
VIJETHA DEGREE COLLEGE [Document title]

Bhaskar Naidu 9
VIJETHA DEGREE COLLEGE [Document title]

WHICH IS
IT'S TIME TO THINK THE
BEST
COLLEGE
FOR DEGREE
SRI SAI
DEGREE COLLEGE
 800+ విద్యార్థులను కలిగి, పట్టణంలో విద్యార్థుల
సంఖ్యలో రెండవ స్థానంలో ఉన్న కళాశాల.
 25+ అర్హత కలిగిన, అనుభవజ్ఞులైన నిబద్దత కలిగిన
అధ్యాపక బృందం.
 పట్టణంలో అత్యధిక ఉత్తీర్ణత శాతం తో పాటు ఉత్తమ గ్రేడ్
పాయింట్లను అత్యధిక విద్యార్థులు సాధించిన కళాశాల.

Bhaskar Naidu 10
VIJETHA DEGREE COLLEGE [Document title]

 అన్ని గ్రూప్ లకు ఇంగ్లీష్ మీడియం మరియు తెలుగు మీడియం


లకు వేరు వేరుగా తరగతులను నిర్వహిస్తున్న కళాశాల.
 అధునాతన సౌకర్యాలతో, విశాలమైన తరగతి గదులు కలిగిన నూతన
భవనము.
 అన్ని సౌకర్యాలు కలిగిన ప్రయోగశాలలో రోజువారీ
ప్రాక్టికల్స్ నిర్వహించు కళాశాల.
 కాంపస్ ఇంటర్వ్యూ లను నిర్వహించి ఉద్యోగాలను
కల్పిస్తున్న కళాశాల.
 కాంపస్ ఇంటర్వ్యూలకు అవసరమైన కమ్యూనికేషన్ మరియు
అర్ధమేటిక్ తరగతుల నిర్వహిస్తున్న కళాశాల.
 డిగ్రీ తరవాత PG, MBA, MCA వంటి ఉన్నత విద్యకు అవసరమైన
బుక్స్ మరియు శిక్షణ ఇస్తున్న కళాశాల.

x 2 21 2 3
y
√ a +b 4 5 6

Bhaskar Naidu 11

You might also like