The space complexity of the given algorithm is:S(P) = C + SP(I) = 1 + 4 = 5Where C is 1 (for constant 40) and SP(I) is 4 (for variables a, b, c, d).Therefore, the space complexity is 5
Presiding Officer Training module 2024 lok sabha electionsanshu789521
More Related Content
Similar to The space complexity of the given algorithm is:S(P) = C + SP(I) = 1 + 4 = 5Where C is 1 (for constant 40) and SP(I) is 4 (for variables a, b, c, d).Therefore, the space complexity is 5
Introduction to Data Structures Sorting and searchingMvenkatarao
Similar to The space complexity of the given algorithm is:S(P) = C + SP(I) = 1 + 4 = 5Where C is 1 (for constant 40) and SP(I) is 4 (for variables a, b, c, d).Therefore, the space complexity is 5 (20)
The space complexity of the given algorithm is:S(P) = C + SP(I) = 1 + 4 = 5Where C is 1 (for constant 40) and SP(I) is 4 (for variables a, b, c, d).Therefore, the space complexity is 5
1. CSC 102 : Introduction to Algorithm Techniques
Department of Computer Science
College of Physical Sciences
Federal University of Agriculture, Abeokuta.
WEEK 2
2019/2020 session
DR. O.E OJO
2. Steps involved in algorithm development
■ Step1. Identification of input: For an algorithm, there are
quantities to be supplied called input and these are fed
externally. The input is to be identified first for any specified
problem.
■ Step2: Identification of output: From an algorithm, at least
one quantity is produced, called for any specified problem.
■ Step3 : Identification the processing operations : All the
calculations to be performed in order to lead to output from
the input are to be identified in an orderly manner.
3. Steps involved in algorithm development
■ Step4 : Processing Definiteness : The instructions
composing the algorithm must be clear and there should not
be any ambiguity in them.
■ Step5 : Processing Finiteness : If we go through the
algorithm, then for all cases, the algorithm should terminate
after a finite number of steps.
■ Step6 : Possessing Effectiveness : The instructions in the
algorithm must be sufficiently basic and in practice they can
be carries out easily.
4. Method for developing an algorithm
■ 1. Define the problem: State the problem that you are trying
to solve in clear and concise terms.
■ 2. List the inputs (information needed to solve the problem)
and the outputs (what the algorithm will produce as a result)
■ 3. Describe the steps needed to convert or manipulate the
inputs or produce the outputs. Start at a high level first and
keep refining the steps until they are effectively computable
operations.
■ 4. Test the algorithm: Choose data sets and verify that your
algorithm works.
5. Example of an Algorithm
Write an algorithm to 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
Step 2: Input the Radius r and PI of the Circle
Step3: PI 3.142
Step4: Area PI * r * r
Step5: Output Area
Step6: Stop
6. Example of an Algorithm
Write an algorithm to find the Sum of two numbers
Initialization
Inputs to the algorithm: First number = A. Second number = B
Expected output: Sum of A and B
Algorithm:
Step 1: Start
Step 2: Sum = 0
Step 3: Input the value of A
Step 4: Input the value of B
Step 5: Sum = A + B
Step 6: Output Sum
Step 7: End
7. Example
■ Design an algorithm to add these test scores: 26, 49, 98,
87, 62, 75 and obtain the Average score
1.Start
2. Sum 0
3. Input 26, 49, 98, 87, 62, 75
4. Sum 26+49+98+87+62+75
5. Average Sum/6
6. Output Average
7. Stop
8. Properties of Algorithm
■ Correctness
Correctness is the property reflecting the extent to which the
algorithm is able to reach a solution without errors.
■ Efficiency
The efficiency of an algorithm is the property that regards the
rapidity by which a solution is reached.
■ Generality
This means that it must solve every instance of the problem.
For example, a program that computes the area of a rectangle
should work on all possible dimensions of the rectangle.
9. ■ Effectiveness
This means that an algorithm must provide the correct
answer to the problem.
■ Comprehensible
Finally the algorithm must be comprehensible by the
one who performs it.
It must describe in all details, the actions and the
entities necessary for the resolution of a problem.
10. Categories of Algorithm
■ From data structure point of view, following are
some important categories of algorithms −
■ Search − Algorithm to search an item in a data structure.
■ Sort − Algorithm to sort items in certain order
■ Insert − Algorithm to insert item in a data structure
■ Update − Algorithm to update an existing item in a data structure
■ Delete − Algorithm to delete an existing item from a data structure
11. One problem(multiple solutions)
■ We design an algorithm to get solution of a given problem. A
problem can be solved in more than one ways.
12. Algorithm Analysis
■ In computer science, the analysis of algorithms is the
determination of the amount of computing resources (such as time
and space) necessary to execute them.
■ We want to be able to consider two algorithms and say that one
is better than the other because it is more efficient in its use of
those resources or perhaps because it simply uses fewer.
13. Algorithm Analysis
■ Algorithm analysis deals with the execution or
running time of various operations involved.
■ Running time of an operation can be defined as no.
of computer instructions executed per operation.
14. Algorithm Analysis
■ Efficiency of an algorithm can be analyzed at two
different stages,
■ before implementation(priori analysis)
■ and after implementation(posterior analysis).
15. Algorithm Analysis
■ It is important to consider the amount of space or
memory an algorithm requires to solve the problem.
■ The amount of space required by a problem solution is
typically dictated by the problem instance itself.
16. Priori Analysis
■ This is theoretical analysis of an algorithm.
■ Efficiency of algorithm is measured by assuming
that all other factors (e.g. Processor speed), are
constant and have no effect on
implementation.
17. Posterior Analysis
■ This is empirical analysis of an algorithm.
■ The selected algorithm is implemented using programming
language.
■ This is then executed on target computer machine.
■ In this analysis, actual statistics like running time and space
required, are collected.
■ Our focus in this course is priori algorithm analysis
18. ALGORITHM COMPLEXITY
■ Suppose X is an algorithm and
■ n is the size of input data,
■ the time and space used by the Algorithm X are the
two main factors which decide the efficiency of X.
■ Time Factor − The time is measured by counting
the number of key operations such as
comparisons in sorting algorithm
19. ALGORITHM COMPLEXITY
■ Space Factor − The space is measured by
counting the
maximum memory space required by the
algorithm.
■ The complexity of an algorithm f(n) gives the
running time
and / or storage space required by the algorithm in
terms of
n as the size of input data.
20. SPACE COMPLEXITY
■ Space complexity of an algorithm represents
the amount of memory space required by the
algorithm in its life cycle.
■ Space required by an algorithm = Fixed Part +
Variable Part.
21. SPACE COMPLEXITY
■ A fixed part is a space required to store certain
data and variables, that are independent of the size
of the problem. Eg: Simple variables & constant
used, program size etc.
■ A variable part is a space required by variables,
whose size depends on the size of the problem.
Eg. Dynamic memory allocation, recursion stack
space etc.
22. SPACE COMPLEXITY
■ Space complexity S(P) of any algorithm P is,
S(P) = C + SP(I)
■ Where C is the fixed part and
■ S(I) is the variable part of the algorithm which
depends on instance characteristic I.
23. SPACE COMPLEXITY
■ Example
Algorithm: SUM (A, B)
Step 1 – START
Step 2 - C ← A + B + 10
Step 3 – Stop.
■ Here we have three variables A, B and C and
one constant.
■ Hence S(P) = 1+3.
■ Therefore, space depends on data types of
given variables and constant types.
24. CLASS WORK 2
■ Question: Find the space complexity in the
algorithm given below:
Algorithm: Addition of numbers
Step 1 – START
Step 2 – a = 40
Step 3- M← a + b +c+ d
Step 4 – Stop.