Module 1
Module 1
Prepared by
Anishamol Abraham
AP, CSE, AJCE
Module 1
Module 1
System Life Cycle
• The system life cycle is a series of stages that are worked through during the
development of a new information system.
• A lot of time and money can be wasted if a system is developed that doesn’t
work properly or do exactly what is required of it.
System Life Cycle-5 Phases
• Requirements
• Analysis
• Design
• Refinement & Coding
• Verification
System Life Cycle
Requirements- Understanding the information you are given (the input) and
what results you are to produce (the output).
• A rigorous description of the input and output which covers all cases.
System Life Cycle
Analysis- Problem breakdown
• Bottom up approach
• Top down approach
System Life Cycle
Design-
• Designer approaches with program needs and operations
• Program need leads to Abstract Data types
• Operations leads to Algorithm specification and algorithm design strategies
• Both are language independent
System Life Cycle
Refinement and coding
• Choose representations for data objects
• Write algorithms for each of the operations on these objects.
• Refine the algorithm
• The order in which you do this may be crucial, because once you choose a
representation, the resulting algorithms may be inefficient.
System Life Cycle
Verification
• Develop correctness proofs for the program
• Testing the program with all variety of inputs
• Remove errors, if any
How to create programs
• Requirements
• Analysis: bottom-up vs. top-down
• Design: data objects and operations
• Refinement and Coding
• Verification
• Program Proving
• Testing
• Debugging
Algorithm
• Definition
An algorithm is a finite set of instructions that accomplishes a particular task.
• Criteria
1. input
2. output
3. definiteness: clear and unambiguous
4. finiteness: terminate after a finite number of steps
5. effectiveness: instruction is basic enough to be carried out
Algorithm Example
• You are given a set of numbers . Youhaveto find the largest value in
thatset.
• Problem Statement : Find the largestnumber in the given list ofnumbers?
• Input : Alist of positive integer numbers. (List must contain at least one
number).
• Output : The largest number in the givenlist of positive integer
numbers.
Algorithm I
• Consider the given list of numbers as 'L' (input), and the largest number as
'max' (Output).
Step 1: Define a variable 'max' and initialize with '0'.
Step 2: Compare first number (say 'x') in the list 'L' with 'max', if 'x' is larger
than 'max', set 'max' to 'x'.
Step 3: Repeat step 2 for all numbers in the list 'L'.
Step 4: Display the value of 'max' as a result.
Algorithm II
• Consider the given list of numbers as 'L' (input), and the largest number as
'max' (Output).
Step 1: Sort the given list in descending order .
Step 2: Assign first element in the list to ‘max’
Step 3: Display the value of 'max' as a result.
Performance Analysis
Assumptions:
*Figure 1.1: Space needed for one recursive call of Program 1.11 (p.21)
Type Name Number of bytes
parameter: float list [ ] 2
parameter: integer n 2
return address:(used internally) 2(unless a far address)
TOTAL per recursive call 6
Time complexity
• Every algorithm requires some amount of computer time to execute its instruction to
perform the task.
• The time complexity of an algorithm is the total amount of time required by an algorithm
to complete its execution.
• Generally, the running time of an algorithm depends upon the following...
• Whether it is running on Single processor machine or Multi processor machine.
• Whether it is a 32 bit machine or 64 bit machine.
• Read and Write speed of the machine.
• The amount of time required by an algorithm to perform Arithmetic operations, logical operations,
return value and assignment operations etc.,
• Input data
Time complexity
• All these factors except input data depends on the system configuration in which
we are executing the program.
• Calculating Time Complexity of an algorithm based on the system configuration is
a very difficult task because the configuration changes from one system to another .
• Actual execution time of an algorithm can be computed only by implementing and
executing the program in a computer.
• It may varies from system to systems.
• It does not seems to be an effective method for analyzing algorithms.
• Hence, requires a unified system model to analyze the algorithm.
Time Complexity
T(P)=C+TP(I)
Compile time (C)
independent of instance characteristics
run (execution) time TP
Definition: TP(n)=caADD(n)+csSUB(n)+clLDA(n)+cstSTA(n)
A program step is a syntactically or semantically meaningful
program segment whose execution time is independent of the
instance characteristics.
Example
– abc = a + b + b * c + (a + b - c) / (a + b) + 4.0
– abc = a + b + c Regard as the same unit
machine independent
Methods to compute the step count
c*g(n)
f(n)
n
n0
c*g(n)
n
n0
n
n0
Eg1:- 3n+2
f(n)=3n+2 ≤ 4n for all n≥2
≤ 4*n
≤ O(n)
More examples
1. Big ‘oh’: The function f(n)=O(g(n)) iff there exist positive
constants c and n0 such that f(n) ≤ c*g(n) for all n , n ≥ n0.
Eg1:- 3n+2
f(n)=3n+2 ≥ 3n for all n≥1
≥ 3*n
≥ Ω(n)
More examples
2. Omega: The function f(n)=Ω(g(n)) iff there exist positive
constants c and n0 such that
f(n) ≥ c*g(n) for all n, n ≥ n0.
Eg 1:- 3n+2
f(n)=3n+2
3n+2 ≤4n for all n≥2
3n+2 ≥3n for all n≥2
3n ≤ 3n+2 ≤ 4n
= Ø(n)
More examples
3. Theta: The function f(n)= Ø(g(n)) iff there exist positive constants c1,c2 and n0
such that
c1g(n) ≤ f(n) ≤ c2 g(n) for all n, n ≥ no.
for(i=0;i<n;i++)
for(j=0;j<n;j++)
printf(“%d”,a[i][j]);
Derive the Big O notation for f(n) = n2+2n+5.
f(n) = n2+2n+5. let g(n) = n2 , f(n) = Og(n) iff.
f(n) <= c*g(n)
n2+2n+5 <= c* n2 n2+2n+5 - c* n2 =0
(1-c) n2+2n+5=0
let n =1
(1-c)+2+5 =0
-c +8 =0 => c = 8.
n2+2n+5 = O(n2 ) , for all the values of c >=8
and n0 >=1
N2+ N = O (N3) Justify your answer..
N2+ N = O (N3) iff
N2+ N <= c*N3
N2+ N - c*N3 = 0
let N =1
1+1-c =0
c =2
Hence we can say that N2+ N = O (N3) for all c >=2and
N0 >= 1