Module1 ADA - 4225 - BCS401 - 12-03-2025
Module1 ADA - 4225 - BCS401 - 12-03-2025
• Body: This part contains the actual instructions and logic that
define how the algorithm solves a problem or performs a task.
It consists of a sequence of operations, computations,
conditionals, and control structures.
Pseudocode Convention
3. An identifier begins with a letter. The data types of variables are not
explicitly declared.
node= record
{
data type 1 data 1;
data type n data n;
node *link;
}
4. There are two Boolean values TRUE and FALSE.
Logical Operators
AND, OR, NOT
Relational Operators
<, <=,>,>=, =, !=
5. Assignment of values to variables is done using the assignment statement.
<Variable>:= <expression>;
Here link is a pointer to the record type node. Individual data items of
a record can be accessed with and period.
Contd…
{
<statement-1>
.
.
.
<statement-n>
}
repeat-until:
repeat
<statement-1>
.
.
.
<statement-n>
until<condition>
Case
{
: <condition-1> : <statement-1>
.
.
.
: <condition-n> : <statement-n>
: else : <statement-n+1>
}
9. Input and output are done using the instructions read & write. No
format is used to specify the size of input or output quantities
Contd…
10. There is only one type of procedure: Algorithm, the heading takes the form,
Algorithm Name (Parameter lists)
consider an example, the following algorithm fields & returns the maximum of
n given numbers:
1. algorithm Max(A,n)
2. // A is an array of size n
3. {
4. Result := A[1];
5. for i:= 2 to n do
6. if A[i] > Result then
7. Result :=A[i];
8. return Result;
9. }
2. Performance Analysis
[Space/Time complexity]
1.Space complexity
S(P) = c + Sp
where c is a constant depends on the fixed part,
Sp is the instance characteristics
Example 1: consider abc() Algorithm.
fixed component depends on a,b and c. The space needed by each of these
algorithms is seen to be the sum of the following component.
• The time T(P) taken by a program P is the sum of the compile time and the
run (or execution)time. The compile time does not depend on the instance
characteristic.
• This run time is denoted by tp (instance characteristic ).
• The execution time or run-time of the program is refereed as its time
complexity denoted by tp (instance characteristics). This is the sum of the
time taken to execute all instructions in the program.
• Exact estimation of runtime is a complex task, as the number of instruction
executed is dependent on the input data. Also different instructions will take
different time to execute. So for the estimation of the time complexity we
count only the number of program steps.
• We can determine the steps needed by a program to solve a
particular problem instance in two ways.
• Initially, the sorted portion is empty, and the entire list is considered
as the unsorted portion.
• In each iteration, the smallest (or largest) element from the unsorted
portion is found and placed at the end of the sorted portion.
• The selection sort algorithm has a time complexity of O(n^2), where n is
the number of elements in the list.