SlideShare a Scribd company logo
FIT NOTES
UNIT-6
[Computer Programming and Languages : algorithm, Flow Chart, Pseudo Code, Program Control Structures,
Programming Languages, Generation of Programming Languages and etc.]
ALGORITHM
A sequential solution of any program that written in human language,called algorithm. Algorithm is
first step of the solution process, after the analysis of problem, programmer write the algorithm of
that problem. Algorithm can be defined as: “A sequence of activities to be processed for getting
desired output from a given input.”
Properties of algorithm
An algorithm should have following properties:
• Finiteness: An algorithm must always terminate after a finite number of steps. It means after
every step one reach closer to solution of the problem and after a finite number of steps
algorithm reaches to an end point.
• Definiteness: Each step of an algorithm must be precisely defined. It is done by well thought
actions to be performed at each step of the algorithm. Also the actions are defined
unambiguously for each activity in the algorithm.
• Input: Any operation you perform need some beginning value/quantities associated with
different activities in the operation. So the value/quantities are given to the algorithm before it
begins.
• Output: One always expects output/result (expected value/quantities) in terms of output from
an algorithm. The result may be obtained at different stages of the algorithm. If some result is
from the intermediate stage of the operation then it is known as intermediate result and result
obtained at the end of algorithm is known as end result. The output is expected
value/quantities always have a specified relation to the inputs
• Effectiveness: Operations of an algorithm should be basic, so that even they can be done
exactly and in a finite amount of time by a person, by using paper and pencil only.
Example of Algorithm
Problem 1: Find the area of a Circle of radius r.
Inputs to the algorithm:
Radius r of the Circle.
Expected output:
Area of the Circle
Algorithm:
Step1: Start
Step2: Input radius of the circle say r
Step3: Use the formula πr2 and store result in a variable AREA
Step4: Print AREA
Step5: Stop
Provided By Shipra Swati
FIT NOTES
Problem2: Write an algorithm to read two numbers and find their sum.
Inputs to the algorithm:
First integer num1.
Second integer num2.
Expected output:
Sum of the two numbers.
Algorithm:
Step1: Start
Step2: Readinput the first num1.
Step3: Readinput the second num2.
Step4: Sum num1+num2 // calculation of sum
Step5: Print Sum
Step6: End
Problem 3: Convert temperature Fahrenheit to Celsius
Inputs to the algorithm:
Temperature in Fahrenheit
Expected output:
Temperature in Celsius
Algorithm:
Step 1: Read temperature in Fahrenheit,
Step 2: Calculate temperature with formula C=5/9*(F-32),
Step 3: Print C.
Advantages of algorithm
1. It is a step-wise representation of a solution to a given problem, which makes it easy to
understand.
2. An algorithm uses a definite procedure.
3. It is not dependent on any programming language, so it is easy to understand for anyone even
without programming knowledge.
4. By using algorithm, the problem is broken down into smaller pieces or steps hence, it is easier
for programmer to convert it into an actual program
Disadvantages of algorithm.
1. Writing algorithm takes a long time.
2. An Algorithm is not a computer program, it is rather a concept of how a program should be.
Provided By Shipra Swati
FIT NOTES
FLOWCHART
A flowchart is the graphical or pictorial representation of a program that uses different standard
symbols. It is a diagram which visually presents the flow of data through processing systems. This
means by seeing a flow chart one can know the operations performed and the sequence of these
operations in a system. Flowchart is drawn according to defined rules and defined set of symbols.
Flowchart Symbols
General Rules for drawing flow chart
1. The Title for every flowchart is compulsory.
2. There must be START and END point for every flowchart.
3. The symbols used in flowchart should have only one entry point on the top. The exit point for
symbols (except for decision/diamond symbol) is on the button.
4. There should be two exit points for decision symbol; exit points can be on the bottom and one
side or on the sides.
5. The flow of flowchart is generally from top to bottom. But in some cases, it can also flow to
upward direction.
6. The direction of the flow of control should be indicated by arrowheads.
Provided By Shipra Swati
FIT NOTES
7. The operations for every step should be written inside the symbol.
8. The language used in flowchart should be simple so that it can be easily understood.
9. The flowlines that show the direction of flow of flowchart must not cross each other.
10. While connecting different pages of the same flowchart, Connectors must be used.
Some examples of Flowcharts
Problem1: Find the area of a circle of radius r.
Problem2: Write an algorithm to read two numbers and find their sum.
Provided By Shipra Swati
FIT NOTES
Problem 3: Convert temperature Fahrenheit to Celsius.
Advantages of flowchart
1. Communication: A Flowchart can be used as a better way of communication of the logic of a
system and steps involve in the solution, to all concerned particularly to the client of system.
2. Effective analysis: A flowchart of a problem can be used for effective analysis of the
problem.
3. Documentation of Program/System: Program flowcharts are a vital part of a good program
documentation. Program document is used for various purposes like knowing the components
in the program, complexity of the program etc.
4. Efficient Program Maintenance: Once a program is developed and becomes operational it
needs time to time maintenance. With help of flowchart maintenance become easier.
5. Coding of the Program: Any design of solution of a problem is finally converted into
computer program. Writing code referring the flowchart of the solution become easy.
Disadvantage of flowchart
1. The flowchart can be complex when the logic of a program is quite complicated.
2. Drawing flowchart is a time-consuming task.
3. Difficult to alter the flowchart. Sometimes, the designer needs to redraw the complete
flowchart to change the logic of the flowchart or to alter the flowchart.
4. Since it uses special sets of symbols for every action, it is quite a tedious task to develop a
flowchart as it requires special tools to draw the necessary symbols.
5. It is just a visualization of a program, it cannot function like an actual program.
Provided By Shipra Swati
FIT NOTES
Type of Algorithms and Flowcharts
Algorithm and flowchart are programming tools. The algorithm and flowchart are classified into
three types of control structures. According to the condition and requirement, these three control
structures can be used.
1. Sequence: In the sequence structure, statements are placed one after the other and the
execution takes place starting from up to down.
All the examples given above represent sequence type of algorithms and flow charts.
2. Branching (Selection): The branch refers to a binary decision based on some condition. If
the condition is true, one of the two branches is explored; if the condition is false, the other
alternative is taken. This is usually represented by the ‘if-then’ construct in pseudo-codes and
programs. In flowcharts, this is represented by the diamond-shaped decision box. This
structure is also known as the selection structure.
Examples:
Problem: write algorithm & Flowchart to find the greater number between two numbers.
Algorithm:
Step1: Start
Step2: Read/input A and B
Step3: If A greater than B then print A.
Step4: if B greater than A then print B.
Step5: End
Flow Chart:
Provided By Shipra Swati
FIT NOTES
Problem: An algorithm & flowchart to find the largest value of any three numbers.
Algorithm:
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
Flowchart:
Problem: Algorithm & flow chart to find roots of quadratic equation ax
2
+bx+c=0
Provided By Shipra Swati
FIT NOTES
Algorithm:
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
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
Flowchart:
Provided By Shipra Swati
FIT NOTES
3. Loop (Repetition): The loop allows a statement or a sequence of statements to be repeatedly
executed based on some loop condition. It is represented by the ‘while’ and ‘for’ constructs in
most programming languages.You must ensure that the condition for the termination of the
looping must be satisfied after some finite number of iterations, otherwise it ends up as an
infinite loop, a common mistake made by inexperienced programmers. The loop is also
known as the repetition structure.
Loops are of two types: Bounded and Unbounded loop. In bounded loop, the number of
iterations is fixed while in unbounded loops the condition has to satisfy to end the loop.
Examples:
Problem: Design an algorithm and flow chart to Print 1 to 20:
Algorithm:
Step 1: Start
Step 2: Initialize X as 0,
Step 3: Increment X by 1,
Step 4: Print X,
Step 5: If X is less than 20 then go back to step 2.
Step 6: End
Flowchart:
Provided By Shipra Swati
=
FIT NOTES
Problem: Design an algorithm and flowchart to input fifty numbers and calculate their sum.
Algorithm:
Step 1: Start
Step 2: Initialize the count variable to zero
Step 3: Initialize the sum variable to zero
Step 4: Read a number say x
Step 5: Add 1 to the number in the count variable
Step 6: Add the number x to the sum variable.
Step 7: Is the count variable in the memory greater than 50?
If yes, display the sum: go to step 8.
If No, Repeat from step 4
Step8: Stop
Flowchart:
Provided By Shipra Swati
x
FIT NOTES
Problem: an algorithm & flowchart to find the Fibonacci series till term≤1000.
Algorithm:
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
Flowchart:
Provided By Shipra Swati
FIT NOTES
Problem: Algorithm & flowchart to calculate factorial of a given number.
Algorithm:
step 1. Start
step 2. Read the number n
step 3. [Initialize]
i=1, fact=1
step 4. Repeat step 4 through 6 until i=n
step 5. fact=fact*i
step 6. i=i+1
step 7. Print fact
step 8. Stop
Flowchart
Provided By Shipra Swati
FIT NOTES
Pseudocode (or Program Design Language)
Pseudocode is one of the tools that can be used to write a preliminary plan that can be developed into
a computer program. Pseudocode is a generic way of describing an algorithm without use of any
specific programming language syntax. It is, as the name suggests, pseudo code —it cannot be
executed on a real computer, but it models and resembles real programming code, and is written at
roughly the same level of detail. Pseudocode, by nature, exists in various forms, although most
syntaxes are borrowed from popular programming languages (like C, Lisp etc). Some important
points are listed below:
• Consists of natural language-like statements that precisely describe the steps of an algorithm
or program
• Statements describe actions
• Focuses on the logic of the algorithm or program
• Avoids language-specific elements
• Written at a level so that the desired programming code can be generated almost
automatically from each statement
• Steps are numbered. Subordinate numbers and/or indentation are used for dependent
statements in selection and repetition structures.
Pseudocode Language Constructs
• Computation/Assignment
▪ Compute var1 as the sum of x and y
▪ Assign expression to var2
▪ Increment counter1
• Input/Output
▪ Input: Get var1, var2, …
▪ Output: Display var1, var2, …
• Selection
▪ IF-else: IF condition THEN (IF condition is true, then do subordinate statement under
IF. If condition is false, then skip statements and execute statements under ELSE)
▪ SWITCH expression TO
◦ case 1: action1
◦ case 2: action 2
◦ etc.
◦ default: action
• Repetition
▪ WHILE condition (while condition is true, then do subordinate statements)
▪ FOR structure (a specialized version of WHILE for repeating execution of statements
a specific number of times i.e. bounds on repetition
▪ DO – WHILE structure (like WHILE, but tests condition at the end of the loop. Thus,
statements in the structure will always be executed at least once.)
Provided By Shipra Swati
FIT NOTES
Pseudocode Example: Express an algorithm to get two numbers from the user (dividend and
divisor), testing to make sure that the divisor number is not zero, and displaying their quotient using
pseudocode
1. Declare variables: dividend, divisor, quotient
2. Prompt user to enter dividend and divisor
3. Get dividend and divisor
4. IF divisor is equal to zero, THEN
4.1. DO
4.1.1. Display error message, “divisor must be non-zero”
4.1.2. Prompt user to enter divisor
4.1.3. Get divisor
4.2. WHILE divisor is equal to zero
5. ENDIF
6. Display dividend and divisor
7. Calculate quotient as dividend/divisor
8. Display quotient
Program Control Structures
Flow of control in any program is implemented with three basic types of control structures:
• Sequential: default mode. Sequential execution of code statements (one line after another)
• Selection: used for decisions, branching -- choosing between 2 or more alternative paths.
Generally there are the types of selection statements:
▪ if
▪ if/else
▪ switch
• Repetition: used for looping, i.e. repeating a piece of code multiple times in a row. In C++,
there are three types of loops:
▪ while
▪ do/while
▪ for
[*** These are explained in previous sections]
Programming Language
A programming language is a vocabulary and set of grammatical rules for instructing a computer or
computing device to perform specific tasks. The term programming language usually refers to high-
level languages, such as BASIC, C, C++, COBOL, Java, FORTRAN, Ada, and Pascal. Each
language has a unique set of keywords (words that it understands) and a special syntax for organizing
program instructions.
Provided By Shipra Swati
FIT NOTES
Generations of Programming Languages
• 1st
generation of programming Language (1GL-1945): In the computer’s first generation,
programmers had to use machine language because no other option was available. It is a
language made up of entirely 1s and 0s, which must be written in accordance with the special
characteristics of a given processor. Each type or family of processor requires its own
machine language. For this reason, machine language is said to be machine-dependent (also
called hardware-dependent). It is also called low-level language. It is the only programming
language that the computer can understand directly without translation.
Machine language programs have the advantage of very fast execution speeds and efficient
use of primary memory.
Use of machine language is very tedious, difficult and time consuming method of
programming.
• 2nd
generation of programming Language (2GL- Mid 1950s): The first step in making
software development easier and more efficient was the creation of Assembly languages.
They are also classified as low-level languages because detailed knowledge of hardware is
still required.
Assembly languages use mnemonic operation codes and symbolic addresses in place of 1s
and 0s to represent the operation codes. A mnemonic is an alphabetical abbreviation used as
memory aid. This means a programmer can use abbreviation instead of having to remember
lengthy binary instruction codes. For example, it is much easier to remember L for Load, A
for Add, B for Branch, and C for Compare than the binary equivalents, which is different
combinations of 0s and 1s.
Before they can be used by the computer, assembly languages must be translated into
machine language. A language translator program called an assembler does this conversion.
Assembly languages provide an easier and more efficient way to program than machine
languages while still maintaining control over the internal functions of a computer at the most
basic level. The advantages of programming with assembly languages are that they produce
programs that are efficient, use less storage, and execute much faster than programs designed
using high-level languages.
Although assembly languages represented an improvement, they had obvious limitations.
Only computer specialists familiar with the architecture of the computer being used can use
them. And because they are also machine dependent, assembly languages are not easily
converted to run on other types of computers.
• 3rd
generation of programming Language (3GL- 1960s to 1980s): Third generation
languages, also known as high-level languages, are very much like everyday text and
mathematical formulas in appearance. They are designed to run on a number of different
computers with few or no changes.
Most high level languages are considered to be procedure-oriented, or Procedural languages,
because the program instructions comprise lists of steps, procedures, that tell the computer not
only what to do but how to do it.
Provided By Shipra Swati
FIT NOTES
A language translator is required to convert a high-level language program into machine
language. Two types of language translators are used with high level languages: compilers
and interpreters.
Objectives of high-level languages
▪ To relieve the programmer of the detailed and tedious task of writing programs in
machine language and assembly languages.
▪ To provide programs that can be used on more than one type of machine with very
few changes.
▪ To allow the programmer more time to focus on understanding the user’s needs and
designing the software required meeting those needs.
Some Examples are COBOL, C, FORTRAN, ADA etc.
• 4th
generation of programming Language (4GL- Mid 1970s to 1990s): Features evident in
fourth generation languages quite clearly are that it must be user friendly, portable and
independent of operating systems, usable by non-programmers, having intelligent default
options about what the user wants and allowing the user to obtain results fasts using minimum
requirement code generated with bug-free code from high-level expressions.
Objectives of fourth generation languages
▪ Increasing the speed of developing programs.
▪ Minimizing user effort to obtain information from computer.
▪ Decreasing the skill level required of users so that they can concentrate on the
application rather than the intricacies of coding, and thus solve their own problems
without the aid of a professional programmer.
▪ Minimizing maintenance by reducing errors and making programs that are easy to
change.
Five basic types of language tools fall into the fourth generation language category.
▪ Query languages
▪ Report generators.
▪ Applications generators.
▪ Decision support systems and financial planning languages.
▪ Some microcomputer application software.
Some Examples are SQL, PHP, Python.
• 5th
generation of programming Language (5GL- 1990s): Natural Languages represent the
next step in the development of programming languages, i.e fifth generation languages. The
text of a natural language statement very closely resembles human speech. Many researchers
speak of 5GL languages as constraint systems. The programmer inputs a set of logical
constraints, with no specified algorithm, and the AI-based compiler builds the program based
on these constraints. It is Used for AI Research, Proof solving, Logical Inference. Some
examples are: Prolog, Mercury
Provided By Shipra Swati

More Related Content

PPTX
Modern Olympic Games
PPTX
Futsal warm up
PDF
How to Scale Google Ads Campaigns?
PPTX
Pole vault
DOCX
Historia del judo
PPTX
Sports Medicine and Doping.pptx
PPTX
International olympic committee
PPTX
Doping control 2014
Modern Olympic Games
Futsal warm up
How to Scale Google Ads Campaigns?
Pole vault
Historia del judo
Sports Medicine and Doping.pptx
International olympic committee
Doping control 2014

Similar to Fundamental of Information Technology - UNIT 6 (20)

PPTX
Algorithm and flowchart.pptx
PPT
PPTX
Algorithms and flow charts
PPTX
flowchart & algorithms
PPTX
Flowchart and algorithm
PPT
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
PPTX
Algorithms-Flowcharts for programming fundamental
PPTX
Unit 1(1).pptx Program Logic Development
PDF
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
PPTX
Data Structures_Introduction to algorithms.pptx
PPTX
Algorithm and flowchart
PPTX
Flowcharts and algorithms
PDF
Algorithm Flowchart Manual ALGORITHM FLOWCHART MANUAL For STUDENTS
PDF
detail of flowchart and algorithm that are used in programmingpdf
PDF
Algorithm manual
PPT
COMPUTER PROGRAMMING UNIT 1 Lecture 4
PDF
ALGORITHM PPT GUIDE.pdf
PPTX
Flowcharting and Algorithm
PPSX
Algorithm and flowchart
PPT
Unit 1 psp
Algorithm and flowchart.pptx
Algorithms and flow charts
flowchart & algorithms
Flowchart and algorithm
BCE L-2 Algorithms-and-Flowchart-ppt.ppt
Algorithms-Flowcharts for programming fundamental
Unit 1(1).pptx Program Logic Development
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
Data Structures_Introduction to algorithms.pptx
Algorithm and flowchart
Flowcharts and algorithms
Algorithm Flowchart Manual ALGORITHM FLOWCHART MANUAL For STUDENTS
detail of flowchart and algorithm that are used in programmingpdf
Algorithm manual
COMPUTER PROGRAMMING UNIT 1 Lecture 4
ALGORITHM PPT GUIDE.pdf
Flowcharting and Algorithm
Algorithm and flowchart
Unit 1 psp
Ad

More from Shipra Swati (20)

PDF
Operating System-Process Scheduling
PDF
Operating System-Concepts of Process
PDF
Operating System-Introduction
PDF
Java unit 11
PDF
Java unit 14
PDF
Java unit 12
PDF
Java unit 7
PDF
Java unit 3
PDF
Java unit 2
PDF
Java unit 1
PDF
OOPS_Unit_1
PDF
Ai lab manual
PDF
Fundamental of Information Technology - UNIT 8
PDF
Fundamental of Information Technology - UNIT 7
PDF
Fundamental of Information Technology
PDF
Disk Management
PDF
File Systems
PDF
Memory Management
PDF
Deadlocks
PDF
Process Synchronization
Operating System-Process Scheduling
Operating System-Concepts of Process
Operating System-Introduction
Java unit 11
Java unit 14
Java unit 12
Java unit 7
Java unit 3
Java unit 2
Java unit 1
OOPS_Unit_1
Ai lab manual
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology
Disk Management
File Systems
Memory Management
Deadlocks
Process Synchronization
Ad

Recently uploaded (20)

PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Pharma ospi slides which help in ospi learning
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Pre independence Education in Inndia.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
STATICS OF THE RIGID BODIES Hibbelers.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Pharma ospi slides which help in ospi learning
O7-L3 Supply Chain Operations - ICLT Program
Complications of Minimal Access Surgery at WLH
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Pre independence Education in Inndia.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPH.pptx obstetrics and gynecology in nursing
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
VCE English Exam - Section C Student Revision Booklet
Module 4: Burden of Disease Tutorial Slides S2 2025
Abdominal Access Techniques with Prof. Dr. R K Mishra
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Supply Chain Operations Speaking Notes -ICLT Program
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table

Fundamental of Information Technology - UNIT 6

  • 1. FIT NOTES UNIT-6 [Computer Programming and Languages : algorithm, Flow Chart, Pseudo Code, Program Control Structures, Programming Languages, Generation of Programming Languages and etc.] ALGORITHM A sequential solution of any program that written in human language,called algorithm. Algorithm is first step of the solution process, after the analysis of problem, programmer write the algorithm of that problem. Algorithm can be defined as: “A sequence of activities to be processed for getting desired output from a given input.” Properties of algorithm An algorithm should have following properties: • Finiteness: An algorithm must always terminate after a finite number of steps. It means after every step one reach closer to solution of the problem and after a finite number of steps algorithm reaches to an end point. • Definiteness: Each step of an algorithm must be precisely defined. It is done by well thought actions to be performed at each step of the algorithm. Also the actions are defined unambiguously for each activity in the algorithm. • Input: Any operation you perform need some beginning value/quantities associated with different activities in the operation. So the value/quantities are given to the algorithm before it begins. • Output: One always expects output/result (expected value/quantities) in terms of output from an algorithm. The result may be obtained at different stages of the algorithm. If some result is from the intermediate stage of the operation then it is known as intermediate result and result obtained at the end of algorithm is known as end result. The output is expected value/quantities always have a specified relation to the inputs • Effectiveness: Operations of an algorithm should be basic, so that even they can be done exactly and in a finite amount of time by a person, by using paper and pencil only. Example of Algorithm Problem 1: Find the area of a Circle of radius r. Inputs to the algorithm: Radius r of the Circle. Expected output: Area of the Circle Algorithm: Step1: Start Step2: Input radius of the circle say r Step3: Use the formula πr2 and store result in a variable AREA Step4: Print AREA Step5: Stop Provided By Shipra Swati
  • 2. FIT NOTES Problem2: Write an algorithm to read two numbers and find their sum. Inputs to the algorithm: First integer num1. Second integer num2. Expected output: Sum of the two numbers. Algorithm: Step1: Start Step2: Readinput the first num1. Step3: Readinput the second num2. Step4: Sum num1+num2 // calculation of sum Step5: Print Sum Step6: End Problem 3: Convert temperature Fahrenheit to Celsius Inputs to the algorithm: Temperature in Fahrenheit Expected output: Temperature in Celsius Algorithm: Step 1: Read temperature in Fahrenheit, Step 2: Calculate temperature with formula C=5/9*(F-32), Step 3: Print C. Advantages of algorithm 1. It is a step-wise representation of a solution to a given problem, which makes it easy to understand. 2. An algorithm uses a definite procedure. 3. It is not dependent on any programming language, so it is easy to understand for anyone even without programming knowledge. 4. By using algorithm, the problem is broken down into smaller pieces or steps hence, it is easier for programmer to convert it into an actual program Disadvantages of algorithm. 1. Writing algorithm takes a long time. 2. An Algorithm is not a computer program, it is rather a concept of how a program should be. Provided By Shipra Swati
  • 3. FIT NOTES FLOWCHART A flowchart is the graphical or pictorial representation of a program that uses different standard symbols. It is a diagram which visually presents the flow of data through processing systems. This means by seeing a flow chart one can know the operations performed and the sequence of these operations in a system. Flowchart is drawn according to defined rules and defined set of symbols. Flowchart Symbols General Rules for drawing flow chart 1. The Title for every flowchart is compulsory. 2. There must be START and END point for every flowchart. 3. The symbols used in flowchart should have only one entry point on the top. The exit point for symbols (except for decision/diamond symbol) is on the button. 4. There should be two exit points for decision symbol; exit points can be on the bottom and one side or on the sides. 5. The flow of flowchart is generally from top to bottom. But in some cases, it can also flow to upward direction. 6. The direction of the flow of control should be indicated by arrowheads. Provided By Shipra Swati
  • 4. FIT NOTES 7. The operations for every step should be written inside the symbol. 8. The language used in flowchart should be simple so that it can be easily understood. 9. The flowlines that show the direction of flow of flowchart must not cross each other. 10. While connecting different pages of the same flowchart, Connectors must be used. Some examples of Flowcharts Problem1: Find the area of a circle of radius r. Problem2: Write an algorithm to read two numbers and find their sum. Provided By Shipra Swati
  • 5. FIT NOTES Problem 3: Convert temperature Fahrenheit to Celsius. Advantages of flowchart 1. Communication: A Flowchart can be used as a better way of communication of the logic of a system and steps involve in the solution, to all concerned particularly to the client of system. 2. Effective analysis: A flowchart of a problem can be used for effective analysis of the problem. 3. Documentation of Program/System: Program flowcharts are a vital part of a good program documentation. Program document is used for various purposes like knowing the components in the program, complexity of the program etc. 4. Efficient Program Maintenance: Once a program is developed and becomes operational it needs time to time maintenance. With help of flowchart maintenance become easier. 5. Coding of the Program: Any design of solution of a problem is finally converted into computer program. Writing code referring the flowchart of the solution become easy. Disadvantage of flowchart 1. The flowchart can be complex when the logic of a program is quite complicated. 2. Drawing flowchart is a time-consuming task. 3. Difficult to alter the flowchart. Sometimes, the designer needs to redraw the complete flowchart to change the logic of the flowchart or to alter the flowchart. 4. Since it uses special sets of symbols for every action, it is quite a tedious task to develop a flowchart as it requires special tools to draw the necessary symbols. 5. It is just a visualization of a program, it cannot function like an actual program. Provided By Shipra Swati
  • 6. FIT NOTES Type of Algorithms and Flowcharts Algorithm and flowchart are programming tools. The algorithm and flowchart are classified into three types of control structures. According to the condition and requirement, these three control structures can be used. 1. Sequence: In the sequence structure, statements are placed one after the other and the execution takes place starting from up to down. All the examples given above represent sequence type of algorithms and flow charts. 2. Branching (Selection): The branch refers to a binary decision based on some condition. If the condition is true, one of the two branches is explored; if the condition is false, the other alternative is taken. This is usually represented by the ‘if-then’ construct in pseudo-codes and programs. In flowcharts, this is represented by the diamond-shaped decision box. This structure is also known as the selection structure. Examples: Problem: write algorithm & Flowchart to find the greater number between two numbers. Algorithm: Step1: Start Step2: Read/input A and B Step3: If A greater than B then print A. Step4: if B greater than A then print B. Step5: End Flow Chart: Provided By Shipra Swati
  • 7. FIT NOTES Problem: An algorithm & flowchart to find the largest value of any three numbers. Algorithm: Step 1: Start Step 2: Declare variables a,b and c. Step 3: Read variables a,b and c. Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop Flowchart: Problem: Algorithm & flow chart to find roots of quadratic equation ax 2 +bx+c=0 Provided By Shipra Swati
  • 8. FIT NOTES Algorithm: Step 1: Start Step 2: Declare variables a, b, c, D, x1, x2, rp and ip; Step 3: Calculate discriminant 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 Flowchart: Provided By Shipra Swati
  • 9. FIT NOTES 3. Loop (Repetition): The loop allows a statement or a sequence of statements to be repeatedly executed based on some loop condition. It is represented by the ‘while’ and ‘for’ constructs in most programming languages.You must ensure that the condition for the termination of the looping must be satisfied after some finite number of iterations, otherwise it ends up as an infinite loop, a common mistake made by inexperienced programmers. The loop is also known as the repetition structure. Loops are of two types: Bounded and Unbounded loop. In bounded loop, the number of iterations is fixed while in unbounded loops the condition has to satisfy to end the loop. Examples: Problem: Design an algorithm and flow chart to Print 1 to 20: Algorithm: Step 1: Start Step 2: Initialize X as 0, Step 3: Increment X by 1, Step 4: Print X, Step 5: If X is less than 20 then go back to step 2. Step 6: End Flowchart: Provided By Shipra Swati =
  • 10. FIT NOTES Problem: Design an algorithm and flowchart to input fifty numbers and calculate their sum. Algorithm: Step 1: Start Step 2: Initialize the count variable to zero Step 3: Initialize the sum variable to zero Step 4: Read a number say x Step 5: Add 1 to the number in the count variable Step 6: Add the number x to the sum variable. Step 7: Is the count variable in the memory greater than 50? If yes, display the sum: go to step 8. If No, Repeat from step 4 Step8: Stop Flowchart: Provided By Shipra Swati x
  • 11. FIT NOTES Problem: an algorithm & flowchart to find the Fibonacci series till term≤1000. Algorithm: 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 Flowchart: Provided By Shipra Swati
  • 12. FIT NOTES Problem: Algorithm & flowchart to calculate factorial of a given number. Algorithm: step 1. Start step 2. Read the number n step 3. [Initialize] i=1, fact=1 step 4. Repeat step 4 through 6 until i=n step 5. fact=fact*i step 6. i=i+1 step 7. Print fact step 8. Stop Flowchart Provided By Shipra Swati
  • 13. FIT NOTES Pseudocode (or Program Design Language) Pseudocode is one of the tools that can be used to write a preliminary plan that can be developed into a computer program. Pseudocode is a generic way of describing an algorithm without use of any specific programming language syntax. It is, as the name suggests, pseudo code —it cannot be executed on a real computer, but it models and resembles real programming code, and is written at roughly the same level of detail. Pseudocode, by nature, exists in various forms, although most syntaxes are borrowed from popular programming languages (like C, Lisp etc). Some important points are listed below: • Consists of natural language-like statements that precisely describe the steps of an algorithm or program • Statements describe actions • Focuses on the logic of the algorithm or program • Avoids language-specific elements • Written at a level so that the desired programming code can be generated almost automatically from each statement • Steps are numbered. Subordinate numbers and/or indentation are used for dependent statements in selection and repetition structures. Pseudocode Language Constructs • Computation/Assignment ▪ Compute var1 as the sum of x and y ▪ Assign expression to var2 ▪ Increment counter1 • Input/Output ▪ Input: Get var1, var2, … ▪ Output: Display var1, var2, … • Selection ▪ IF-else: IF condition THEN (IF condition is true, then do subordinate statement under IF. If condition is false, then skip statements and execute statements under ELSE) ▪ SWITCH expression TO ◦ case 1: action1 ◦ case 2: action 2 ◦ etc. ◦ default: action • Repetition ▪ WHILE condition (while condition is true, then do subordinate statements) ▪ FOR structure (a specialized version of WHILE for repeating execution of statements a specific number of times i.e. bounds on repetition ▪ DO – WHILE structure (like WHILE, but tests condition at the end of the loop. Thus, statements in the structure will always be executed at least once.) Provided By Shipra Swati
  • 14. FIT NOTES Pseudocode Example: Express an algorithm to get two numbers from the user (dividend and divisor), testing to make sure that the divisor number is not zero, and displaying their quotient using pseudocode 1. Declare variables: dividend, divisor, quotient 2. Prompt user to enter dividend and divisor 3. Get dividend and divisor 4. IF divisor is equal to zero, THEN 4.1. DO 4.1.1. Display error message, “divisor must be non-zero” 4.1.2. Prompt user to enter divisor 4.1.3. Get divisor 4.2. WHILE divisor is equal to zero 5. ENDIF 6. Display dividend and divisor 7. Calculate quotient as dividend/divisor 8. Display quotient Program Control Structures Flow of control in any program is implemented with three basic types of control structures: • Sequential: default mode. Sequential execution of code statements (one line after another) • Selection: used for decisions, branching -- choosing between 2 or more alternative paths. Generally there are the types of selection statements: ▪ if ▪ if/else ▪ switch • Repetition: used for looping, i.e. repeating a piece of code multiple times in a row. In C++, there are three types of loops: ▪ while ▪ do/while ▪ for [*** These are explained in previous sections] Programming Language A programming language is a vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks. The term programming language usually refers to high- level languages, such as BASIC, C, C++, COBOL, Java, FORTRAN, Ada, and Pascal. Each language has a unique set of keywords (words that it understands) and a special syntax for organizing program instructions. Provided By Shipra Swati
  • 15. FIT NOTES Generations of Programming Languages • 1st generation of programming Language (1GL-1945): In the computer’s first generation, programmers had to use machine language because no other option was available. It is a language made up of entirely 1s and 0s, which must be written in accordance with the special characteristics of a given processor. Each type or family of processor requires its own machine language. For this reason, machine language is said to be machine-dependent (also called hardware-dependent). It is also called low-level language. It is the only programming language that the computer can understand directly without translation. Machine language programs have the advantage of very fast execution speeds and efficient use of primary memory. Use of machine language is very tedious, difficult and time consuming method of programming. • 2nd generation of programming Language (2GL- Mid 1950s): The first step in making software development easier and more efficient was the creation of Assembly languages. They are also classified as low-level languages because detailed knowledge of hardware is still required. Assembly languages use mnemonic operation codes and symbolic addresses in place of 1s and 0s to represent the operation codes. A mnemonic is an alphabetical abbreviation used as memory aid. This means a programmer can use abbreviation instead of having to remember lengthy binary instruction codes. For example, it is much easier to remember L for Load, A for Add, B for Branch, and C for Compare than the binary equivalents, which is different combinations of 0s and 1s. Before they can be used by the computer, assembly languages must be translated into machine language. A language translator program called an assembler does this conversion. Assembly languages provide an easier and more efficient way to program than machine languages while still maintaining control over the internal functions of a computer at the most basic level. The advantages of programming with assembly languages are that they produce programs that are efficient, use less storage, and execute much faster than programs designed using high-level languages. Although assembly languages represented an improvement, they had obvious limitations. Only computer specialists familiar with the architecture of the computer being used can use them. And because they are also machine dependent, assembly languages are not easily converted to run on other types of computers. • 3rd generation of programming Language (3GL- 1960s to 1980s): Third generation languages, also known as high-level languages, are very much like everyday text and mathematical formulas in appearance. They are designed to run on a number of different computers with few or no changes. Most high level languages are considered to be procedure-oriented, or Procedural languages, because the program instructions comprise lists of steps, procedures, that tell the computer not only what to do but how to do it. Provided By Shipra Swati
  • 16. FIT NOTES A language translator is required to convert a high-level language program into machine language. Two types of language translators are used with high level languages: compilers and interpreters. Objectives of high-level languages ▪ To relieve the programmer of the detailed and tedious task of writing programs in machine language and assembly languages. ▪ To provide programs that can be used on more than one type of machine with very few changes. ▪ To allow the programmer more time to focus on understanding the user’s needs and designing the software required meeting those needs. Some Examples are COBOL, C, FORTRAN, ADA etc. • 4th generation of programming Language (4GL- Mid 1970s to 1990s): Features evident in fourth generation languages quite clearly are that it must be user friendly, portable and independent of operating systems, usable by non-programmers, having intelligent default options about what the user wants and allowing the user to obtain results fasts using minimum requirement code generated with bug-free code from high-level expressions. Objectives of fourth generation languages ▪ Increasing the speed of developing programs. ▪ Minimizing user effort to obtain information from computer. ▪ Decreasing the skill level required of users so that they can concentrate on the application rather than the intricacies of coding, and thus solve their own problems without the aid of a professional programmer. ▪ Minimizing maintenance by reducing errors and making programs that are easy to change. Five basic types of language tools fall into the fourth generation language category. ▪ Query languages ▪ Report generators. ▪ Applications generators. ▪ Decision support systems and financial planning languages. ▪ Some microcomputer application software. Some Examples are SQL, PHP, Python. • 5th generation of programming Language (5GL- 1990s): Natural Languages represent the next step in the development of programming languages, i.e fifth generation languages. The text of a natural language statement very closely resembles human speech. Many researchers speak of 5GL languages as constraint systems. The programmer inputs a set of logical constraints, with no specified algorithm, and the AI-based compiler builds the program based on these constraints. It is Used for AI Research, Proof solving, Logical Inference. Some examples are: Prolog, Mercury Provided By Shipra Swati