+ All Categories
Home > Documents > Complexity (1)

Complexity (1)

Date post: 01-Oct-2015
Category:
Upload: usama-chaudhary
View: 227 times
Download: 4 times
Share this document with a friend
Description:
Big-Oh Notation
Popular Tags:
30
Page:1 Dr. Mehreen Saeed CSC 201:Data Structures and Algorithms SPRING 2015 Complexity Analysis Text is mainly from Chapter 2 by Drozdek
Transcript

Lesson 1

Complexity AnalysisText is mainly from Chapter 2 by DrozdekPage:#Dr. Mehreen SaeedCSC 201:Data Structures and AlgorithmsSPRING 2015

1Computational complexityDeveloped by Juris Hartmanis & Richard E. StearnsCompares efficiency of algorithmsAssesses the degree of difficulty of an algorithmHow much effort is needed to APPLY an algorithmEstimate the resources required by an algorithmHow costly it isPage:#Dr. Mehreen SaeedCSC 201:Data Structures and AlgorithmsSPRING 2015

What is the COST of an algorithm???Time SpacePage:#Dr. Mehreen SaeedCSC 201:Data Structures and AlgorithmsSPRING 2015

How can you practically compare 2 algorithms???Run them on the same machineImplement them using the same languageOnly time units such as nano-seconds or micro seconds should not be usedWHY???Logical units expressing the relation between the size of file n and the amount of time t required to process it should be usedSame input data should be used

Page:#Dr. Mehreen SaeedCSC 201:Data Structures and AlgorithmsSPRING 2015

Problems with this approachEffort One program may be better written than the otherChoice of tests may favor one of the algorithmsWe want a method in which we compare two algorithms WITHOUT executing themThe method should be independent of hardware/compiler/operating systemPage:#Dr. Mehreen SaeedCSC 201:Data Structures and AlgorithmsSPRING 2015

What do we need?????We require algorithm analysis!!!Estimate the performance of an algorithm throughThe number of operations required to process an inputProcess an input of certain size Require a function expressing relation between n & t called time complexity function T(n)For calculating T(n) we need to compute the total number of program steps (can be the number of executable statements or meaningful program segment)Page:#Dr. Mehreen SaeedCSC 201:Data Structures and AlgorithmsSPRING 2015

Calculating T(n)A program step is the syntactically / semantically meaningful segments of a programA step DOESNOT correspond to a definite time unitA step count is telling us how run time for a program changes with change in data sizeCalculate the total number of steps/executable statements in a programFind the frequency of each statement and sum them upDont count comments and declarations

Page:#Dr. Mehreen SaeedCSC 201:Data Structures and AlgorithmsSPRING 2015

Analysis of for Loop1:for (i=0;i


Recommended