Lecture02 Week 1
Lecture02 Week 1
Definition:
An algorithm is defined as the finite steps followed in order to solve the
given problem.
Characteristic of algorithm:
11/05/2023 8
START AND STOP
COMPUATIONAL
DECESION MAKING
CONNECTOR
FLOW INDICATOR
11/05/2023 9
Pseudocode:
Pseudocode is an artificial and informal language that helps the programmers to develop algorithm in the text format. It allows the
programmer to focus on the logic of the algorithm without being distracted by details of the language syntax. It narrates steps of the
algorithm more precisely.
• Following are the keywords used to indicate input, output and other operations.
• Input – READ, GET
• Output – PRINT, DISPLAY
• Compute – CALCULATE, DETERMINE
• Initialize SET, INT
• Add one – INCREMENTER
• Sub one- DECREMENTER
• Conditions and loops
– IF-THEN ELSE
– Repetitive execution
– WHILE
– CASE
– REPEAT UNTIL
– FOR
11/05/2023 10
• Pseudocode to obtain sum of two numbers. BEGIN
INPUT X,Y
DETERMINE SUM = X+Y PRINT SUM
END
We can design a program by going through the following first four
major steps:
• Analyze the program.
• Design a solution/Program
• Code/Enter the program
• Test the program
• Evaluate the solution.
11/05/2023 12
• Analyze the program: When we analyze a problem, we think about the
requirements of the program and how the program can be solved.
• Design a solution/Program: This is the stage where we decide how our
program will work to meet the decision made during analysis. Program
design does not require the use of a computer. We can design program
using pencil and paper. This is the stage where algorithm are
designed.
• Code/Enter the Program: Here we enter the program into the
machine by making use of suitable programming language.
• Test the Program: This part deals with testing of programs for various
inputs and making necessary changes if required. Testing cannot show
that a program produces the correct output for all possible inputs,
because there are typically an infinite number of possible inputs. But
testing can reveal syntax errors, run-time problems and logical mistakes.
11/05/2023 13
• Evaluate The solution: Thus, finally program can be implementing to
obtain desired results. Here are some more points to be considered
while designing a program.
– Use of procedures.
– Choice of variable names.
– Documentation of program
– Debugging program
– Testing.
Use of procedures:
Procedures is a part of code used to carry out independent task. Separate
procedures could be written to carry out different task and then can be
combined and linked with the main procedure. This will help in making the
algorithm and eventually programs readable and modular.
11/05/2023 14
• Choice of variable: We can make programs more meaningful and easier to
understand by choosing appropriate variable and constant names. For
example: if wish to store age of two different people we can define
variable age1,age2 to store their ages. The main advantage of choosing
correct variable is that the program becomes self explanatory.
11/05/2023 16
• Program Testing: The program should be tested against many possible inputs.Some of
the things we might check are whether the program solves the smallest possible
problem, whether it may not be possible or necessary to write programs that handle
all input conditions, all the time. Whenever possible, programs should be
accomplished by input and output section.
• Here are some desirable characteristics of program
– Integrity:R3fer to the accuracy of the program.
– Clarity: Refer to the overall readability of the program, with emphasis on its underlying
logic.
– Simplicity: The clarity and accuracy of the program are usually enhanced by keeping the things
as simple as possible, consistent with the overall program objectives.
– Efficiency: It is concerned with the execution speed and efficient memory utilization.
– Modularity:Many program can be decomposed into a
independent procedures or modules.
– Generality: Program must be as general as possible.
11/05/2023 17
11/05/2023 18