0% found this document useful (0 votes)
1 views

lecture3(Mesuring input)

The document discusses the analysis of algorithms focusing on correctness, time efficiency, space efficiency, and optimality. It outlines theoretical and empirical approaches to measure time efficiency, including best-case, average-case, and worst-case scenarios. The conclusion emphasizes the importance of order of growth in algorithm efficiency and the use of notations like big O, big Omega, and big Theta for comparison.

Uploaded by

abhiishek260
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

lecture3(Mesuring input)

The document discusses the analysis of algorithms focusing on correctness, time efficiency, space efficiency, and optimality. It outlines theoretical and empirical approaches to measure time efficiency, including best-case, average-case, and worst-case scenarios. The conclusion emphasizes the importance of order of growth in algorithm efficiency and the use of notations like big O, big Omega, and big Theta for comparison.

Uploaded by

abhiishek260
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

CSE408

Measuring of input size &


running time

Lecture #3
Analysis of algorithms

Issues:
• correctness
• time efficiency
• space efficiency
• optimality

Approaches:
• theoretical analysis
• empirical analysis
Theoretical analysis of time efficiency

Time efficiency is analyzed by determining the number of


repetitions of the basic operation as a function of input size

Basic operation: the operation that contributes most towards


the running time of the algorithm
input size

T(n) ≈ copC(n)
running time execution time Number of times
for basic operation basic operation is
executed
Empirical analysis of time efficiency

Select a specific (typical) sample of inputs

Use physical unit of time (e.g., milliseconds)


or
Count actual number of basic operation’s executions

Analyze the empirical data


Best-case, average-case, worst-case

For some algorithms efficiency depends on form of input:

Worst case: Cworst(n) – maximum over inputs of size n

Best case: Cbest(n) – minimum over inputs of size n

Average case: Cavg(n) – “average” over inputs of size n


• Number of times the basic operation will be executed on typical input
• NOT the average of worst and best case
• Expected number of basic operations considered as a random variable under
some assumption about the probability distribution of all possible inputs
Example: Sequential search

Worst case

Best case

Average case
Example

Let’s consider again sequential search. The standard assumptions


are that (a) the probability of a successful search is equal to p
(0 ≤ p ≤ 1) and (b) the probability of the first match occurring
in the ith position of the list is the same for every i.
we can find the average number of key comparisons Cavg(n) as
follows. In the case of a successful search, the probability of
the first match occurring in the ith position of the list is p/n for
every i, and the number of comparisons made by the algorithm
in such a situation is obviously i. In the case of an unsuccessful
search, the number of comparisons will be n with the
probability of such a search being (1− p). Therefore,
Types of formulas for basic operation’s count

Exact formula
e.g., C(n) = n(n-1)/2

Formula indicating order of growth with specific multiplicative


constant
e.g., C(n) ≈ 0.5 n2

Formula indicating order of growth with unknown


multiplicative constant
e.g., C(n) ≈ cn2
Order of growth

Most important: Order of growth within a constant multiple as


n→∞

Example:
• How much faster will algorithm run on computer that is twice
as fast?

• How much longer does it take to solve problem of double


input size?
Values of some important functions as n → 
Conclusion

• The efficiency analysis framework concentrates on the order of growth of


an algorithm’s basic operation count as the principal indicator of the
algorithm’s
• To compare and rank such orders of growth, computer scientists use three
notations:(big oh), (big omega), and (big theta)efficiency
The efficiency analysis framework concentrates
on the order of growth of an algorithm’s basic operation count as
the principal indicator of the algorithm’s

To compare and rank such orders of growth, computer scientists


use three notations:(big oh), (big omega), and
(big theta)efficiency

You might also like