Anda di halaman 1dari 10

Software(Algorithm)

Quality
Correctness
Efficiency

Correctness
Formal

Correctness Proof:
No practical general method due to
complexity of software -> Limited
application and hence Very impractical.
Testing:
Repeatedly test-running a program.
Key factors:
1. Thoroughness (How many times to test
and how
effectively to cover all possible execution
paths of
the program?)
2. Selection of test input cases: A different

Efficiency
Two

factors
1. execution speed (execution
time)
2. memory requirement
Execution time is more critical as
memory size can be increased at
relatively low cost due to
technology advances.
Exact execution time is not only
difficult to measure but also not

Exact execution time


Varies

(for the same program) due to


many affecting factors such as
1. computer hardware speed
2. qualities of operating systems
including
compilers and data transfer (between
main memory and secondary
memory)
speed and
3. inputs.

Relative execution time


More

significant as generally larger inputs


cause execution time to increase.
Focus: Whether program terminates
reasonably quickly for sufficiently large
inputs, which has a lot to do with the rate
at which actual execution time goes up as
input size goes up, the smaller the rate the
more likely program terminates reasonably
fast for large inputs.
So relative execution time is sought as all
above affecting factors are to be absorbed
into such relative time measures.

Relative Time Measures


Absolute

(actual) execution time:


Meaningless and Impractical
Use of asymptotic notations for The Order
of O-notation.
O(n3): Represents any value (time or
anything) that is not greater than c*n3 for
a certain fixed constant c when the
parameter n is sufficiently large. So, it
represents a set of all such possible values
acting as an upper bound of a quantity
(time or otherwise) we are interested in.

O(n )
3

Represents

all possible functions, g(n), such that


g(n) <= c1*n3 for a certain constant c1 if n is
sufficiently large (more precisely if n >= c 2 for a
certain constant c2)

So

each of the following functions are in O(n3):


99900000*n3 + 100000000*n2 + n
100000000000*n2
100000000*n2 *logn + 10000000000*n3

But,

none of the following is:


999*n3 + 0.00000001*n3*logn
0.00000009*n3.3
0.000000000002*n4
0.0000000003*1.1n

How to get the O-function


O-function

is referred to as the Time


complexity function (of a program or an
algorithm).
We assume that each elementary
operation takes a time no greater than
a fixed constant time (in a certain unit
of time). These elementary operations
include binary arithmetic operations,
binary logical operations, assignments,
branching, etc. But they may not
include data movements.

How to get the O-function


(Cont.)
Example-1:

for (m=1; m<=n; m++)


{ for (k=1; k<=2*n; k++)
`
{ cin > a, b, c, d; funfunction(a,b,c); //s-1}
cout < a+b*c*d^10; //s-2
}
Statement s-1 is executed no more than 2*n 2 times
each time taking a time no greater than a constant,
say c1, and statement s-2 is executed no more than
n times, each time taking a time no greater than a
constant, say c2.
So,

the total time is no greater than 2*c1* n2 + c2* n.

So,

it is in O(n2), that is, it is Quadratic.

How to get the O-function


(Cont.)

Example-2 (Recursive function)


int good (n)
{

cout > It is nice to be alive!!!!!!!;

if (n==0 |n==1) return n;


else return good(n-1)*good(n-2)*n*n;
}

We would like to find a time complexity function for the above function.

Let t(n) be the actual time for execution given the parameter n.
We see that if n=0 or n=1, t(n) = a certain constant time c 1 .
Otherwise, that is, if n>=2, t(n) = c1 + t(n-1) + t(n-2) + c2 .
t(n) = c3 + t(n-1) + t(n-2) for yet another constant c3

As we see, t(n) involves a recurrence relation and hence, we need to


solve this recurrence relation to find out t(n) and its O-function.

Anda mungkin juga menyukai