Top Banner
Analysis of Algorithms Kasun Ranga Wijeweera (Email: [email protected])
15

Analysis of Algorithms

Dec 17, 2022

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Analysis of Algorithms

Analysis of Algorithms

Kasun Ranga Wijeweera(Email:

[email protected])

Page 2: Analysis of Algorithms

Keywords• Algorithm: A well defined finite set of steps a computer follows to solve a problem

• Algorithm Analysis: The process of determining the amount of resources required during the execution of an algorithm

• Computer Program: An instance , or concrete representation, for an algorithm in some programming language

Page 3: Analysis of Algorithms

Properties of Algorithms• It must be correct• It must be composed of a series of concrete steps

• There can be no ambiguity as to which step will be performed next

• It must be composed of a finite number of steps• It must terminate

Page 4: Analysis of Algorithms

Why Analyze Algorithms?• An algorithm can be analyzed in terms of time and space. The running time of an algorithm is influenced by several factors

Speed of the machine running the program Language in which the program was written Efficiency of the compiler that created the program

The size of the input Organization of the input

Page 5: Analysis of Algorithms

Two Conflicting Goals• There are often many approaches (algorithms) to solve a problem. How do we choose between them?

• At the heart of computer program design there are two (sometimes conflicting) goals

Goal ONE: To design an algorithm that is easy to understand, code, debug Software Engineering

Goal TWO: To design an algorithm that makes efficient use of the computer’s resources Data Structures and Algorithm Analysis

Page 6: Analysis of Algorithms

Natural Size of a Problem• The problems have a natural “size” (N)• N = Amount of data to be processed• Resources used is proportional to f(N)• f is a function• Resource is most often time

Page 7: Analysis of Algorithms

Definitions• Average Case: The amount of time a program might be expected to take on “typical” input data

• Worst Case: The amount of time a program would take on the worst possible input configuration

Page 8: Analysis of Algorithms

Experimental Comparison• Consider a C program• C program Machine code• How long one C statement might take to execute?• Several problems arise in experimental comparison

Resources are being shared Some programs are extremely sensitive to their input data

Many programs of interest are not well understood

Page 9: Analysis of Algorithms

A Framework for Analysis• Characterize the data that is to be used as input and decide what type of analysis is appropriate: Determined by the properties of the algorithm

• Identify abstract operations upon which the algorithm is based: Determined by the properties of the computer

• Proceeding the mathematical analysis itself to find worst and average case values

Page 10: Analysis of Algorithms

The Upper Bound of Running Time• The running time is always less than some “upper bound” no matter what the input

• Worst case running time corresponds to that upper bound

• Average case running time corresponds to the time taken for a random input of data

Page 11: Analysis of Algorithms

Algorithm Profiling• While the number of abstract operations involved can be in principle large, it is usually the case that the performance of the algorithms we consider depends on only a few quantities

• Example: Instruction Frequency Counts• A Quote: “90% of the time is spent in 10% of the code”

Page 12: Analysis of Algorithms

The Cyclic Process of Analysis• Analysis of an algorithm is a cyclic process

Analyze

Refine

Estimate

Improvements to the implementation

Page 13: Analysis of Algorithms

Reference

Page 14: Analysis of Algorithms

Any Questions?

Page 15: Analysis of Algorithms

Thank You!