The document discusses algorithms and their key characteristics. It defines an algorithm as a set of well-defined steps to solve a problem. Algorithms must be precise, terminate in a finite time, and not repeat infinitely. The document provides examples of algorithm problems and their solutions, and discusses common ways to represent algorithms as programs, flowcharts, or pseudocode. Flowcharts use symbols to visually represent the logic and sequence of operations.
2. Programmer’s model of a computer
algorithms
In programming, algorithm is a set of well defined
instructions in sequence to solve the problem.
The correct sequence of instructions needed to
solve the corresponding problem.
The term algorithm refers to the logic of a
program.
It is a step by step description of how to arrive at
a solution to a given problem.
3. Characteristics
Each instruction should be precise and
unambiguous.
Each instruction should be executed in a finite
time.
No instruction should repeat infinitely. This
ensures that the algorithm terminates ultimately.
After executing the instructions (when the
algorithm terminates), the desired results are
obtained.
4. Sample Algorithm
Problem1 :
Fifty students in a class appeared in their final
examination. The division column of their mark
sheets contains the division(FIRST, SECOND,
THIRD or FAIL) obtained by them. If their mark
sheets are available with you, write an algorithm
to calculate and print the total number of students
who in FIRST division.
5. Algorithm Step
Step 1: Initalize Total_First_Division and
Total_Marksheets_Checked to zero.
Step 2: Take the mark sheet of the next student.
Step 3: Check the division column of the mark sheet
to see if it is FIRST. If no, go to Step 5.
Step 4: Add 1 to Total_First_Division.
Step 5: Add 1 to Total_Marksheets_Checked.
Step 6: Is Total_Marksheets_Checked=50?. If no,go
to Step 2.
Step 7: Print Total_First_Division.
Step 8 : Stop
6. Representation of Algorithm
Commonly used ways to represent an algorithm are :
As program
As flowchart
As pseudocode
7. Flow Chart
A Flowchart is a pictorial representation of an
algorithm.
Programmers often use it as a program-planning tool
for visually organizing a sequence of steps necessary
to solve a problem using a computer.
It uses boxes of different shapes to denote different
types of instructions.
Programmers write actual instructions within these
boxes using clear and concise statements.
Direct solid lines connecting these boxes indicate flow
of operations – sequence in which to execute the
instructions.
The process of drawing a flowchart for an algorithm is
known as flowcharting.
8. WHY USE FLOWCHARTS?
Normally two steps 1. Algo 2. flowchart for preparing
program.
Advantage of two steps approach in program writing
is that
Programmer can concentate fully on the logic of the
solution to the problem at hand, without paying
attention to the syntax and other details of the
programming language.
Flow chart shows the flow of operations in pictorial
form, a programmer can detect any error in the logic
with greater ease than in the case of a program.
Once the flowchart is ready, the programmer can
concentrate on coding the operations in each box of
the flowchart as statements of the programming
language.
9. FLOWCHART SYMBOLS
A flowchart uses boxes of different shapes to denote
different types of instructions.
The use of symbols having standardized meanings
makes it easier to communicate program logic
through flowcharts.
Terminal Input/Output Processing
Decision Flow lines Connectors
11. Sample Flowchart
1. A student appears for an examination
consisting of total 10 subjects with each subject
having maximum marks of 100. The student’s roll
number, name and marks obtained by him/her in
various subjects are input data.Such a collection
of related data items, treated as a unit, is known
as a record. Draw a flowchart for the algorithm to
calculate the percentage marks obtained by the
student, and to print it with his/her roll number
and name.
12. 2. Fifty students of a class appear in the
examination of below example1 .Draw a flowchart
for the algorithm to calculate and print the
percentage marks obtained by each student
along with his/her roll number and name.
13. For the examination of below example1, we want
to make a list of only those students who passed
the examination (obtained 30% or more marks).
In the end, we also want to print the total number
of students who passed. A trailer record having
sentinel value of 9999999 for Rollno terminates
input data of all students. Draw a flowchart for an
algorithm to process this requirement.
14. Input data of each student for the examination of
example1 also contains information regarding
his/her sex in a field named Sexcode having
value M (for male) or F(for female). We want to
make a list of only those female students who
passed in second division(obtained 45% or more
but less than 60% marks.) In the end, we also
want to print the total number of such students. A
trailer record having a sentinel value of Z for
Sexcode terminates input data of all students.
Draw a flowchart for an algorithm to process this
requirement.
15. Levels of Flowcharts
There are no set standards on the amount of
detail required in flowchart.A flowchart that
outlines the main segments of a program (shows
only broad details) is a macro flowchart, and a
flowchart with more details is a micro
flowchart(also called detailed flowchart).
16. Flowcharting Rules
The basic flowcharting rules and guidelines are as follows:
1. First chart the main line of logic, and then incorporate deatails.
2. Maintain a consistent level of details for a given flowchart.
3. Do not chart every detail in a flowchart; otherwise, the
flowchart will only be a graphic representation of all the steps
of the corresponding program. A reader interested in details
can refer to the program itself.
4. Use common statements that are easy to understand for words
within flowchart symbols. Use descriptive titles written in your
own language, rather than machine-oriented language.
5. Be consistent in using names and variables in a flowchart.
6. Go from left to right and top to bottom in constructing a
flowchart.
7. Keep a flowchart as simple as possible, and avoid crossing of
flow lines.
8. If you need a new page while drawing a flowchart, break the
flowchart at an input or output point. Moreover, use properly
labeled connectors to link portions of the flowchart on different
pages.
17. Advantage and Limitations of
Flowcharts
Advantage
Better communication
Effective analysis
Effective synthesis
Proper program documentation
Efficient coding
Systematic debugging
Systematic testings
18. Limitations
Flowcharts are very time consuming and laborious to draw
with proper symbols and spacing, especially for large
complex programs. You can very well imagine how difficult
it would be to develop a detailed flowchart for a program
containing over 50000 statements.
Any change and modification in program logic usually
requires a completely new flowchart. Redrawing a
flowchart being a tedious task
Many companies use software tools that generate
flowcharts automatically from program code.
This backward approach draws flowcharts from program
codes mainly for documentation purpose.
There are no standards determining the amount of detail
that should be included in a flowchart.
Because of such limitations, many organizations have
reduced the amount of flowcharting used. In its place they
use alternative tools for program analysis, two of which are
described below.
19. Bisection Method#include<stdio.h>
#define e 0.001
#define f(x) x*x*x -4*x +1
Void main()
{
float x0,x1,x2;
float f0,f1,f2;
clrscr();
printf(“Enter the values of x0 and x1”);
scanf(“%f%f”,&x0,&x1);
do{
f0 = f(x0);
f1 = f(x1);
x2=(x0+x1)/2;
f2=f(x2);
if(f0*f2<0)
{
x1=x2;
}
else
{
x0=x2;
}
i++;
printf(“No. of Iterations:=%d”,i);
printf(“Root:=%f”,x2);
printf(“Value of function =%fn”,f2);
}while(fabs(f2)<e);
getch();
}
20. Basic structure and functioning of
computers with a PC as as
illustrative example
25. Operating system with DOS as an
example
MS-DOS stands for Microsoft Disk Operating
System.
It is a single-user operating system for IBM and
IBM compatible personal computers.
Microsoft and IBM introduced it jointly in 1981.
It was the most popular OS for personal
computers in the 1980’s .
Because of its popularity,Microsoft later took a
decision to launch independently Microsoft
Windows operating system in 1990s.
26. Structure of MS-DOS
MS-DOS has the following three layers:
1. BIOS 2. Kernel 3. Shell
BIOS: stands for Basic Input Output System.
It contains device drivers for standard devices such
as keyboard,disk,floppy, printer, and display monitor.
It also contains basic low-level services such as time-
of-day and system configuration analysis.
With hardware-dependent services in a BIOS, the
operating system ensures that it can offer other
higher-level operating system services in a hardware-
independent manner.
This enables those operating system services to be
portable easily to other machines.
Usually, computer manufecturers (not Microsoft)
supply the BIOS.
Generally, the BIOS is located, in part, in a ROM,
which is a non-erasable memory.
27. BIOS
When a user switches on a computer, the
computer’s hardware transfers control to the
bootstrap procedure of the BIOS in ROM.
The bootstrap procedure carries out some
hardware tests to check whether the memory and
other hardware devices are functioning properly.
If the hardware tests pass successfully, the
bootstrap procedure loads into memory a small
portion of the operating system from disk.
This part of the operating system then loads the
rest of the mem