23
Algorithm Complexity Analyzing By Haluan Mohammad Irsad

Algorithm Analyzing

Embed Size (px)

Citation preview

AlgorithmComplexityAnalyzingByHaluanMohammadIrsad

AlgorithmComplexity

• CommonlyexpressedinBigONotation“isamathematicalnotationthatdescribesthe limitingbehavior ofa function whentheargumenttendstowardsaparticularvalueorinfinity.”

“Representingthegrowthrateofanalgorithmbasedontime andspace”

Measurement

• Timecomplexity:howlongdoesthealgorithmrun?• Spacecomplexity:thenumberofmemorycellswhichanalgorithmneeds

Exclude

• Platform(machine/hardware&OS)• ProgrammingLanguage• CompilerQuality• ProgrammingParadigm

CodeExample

ConstantAlgorithmO(1)

LinearAlgorithmO(n)

AlgorithmO(logn)

QuadraticAlgorithmO(n2)

CubicAlgorithmO(n3)

BenchmarkbyDataStructure

BenchmarkbySortingOperation

DataTest

Problem

Count1and0inaline.Ifinthelinehave1digitineventhenprint1,else print0.

ExampleResult

Input Output

DataTest

Sizeofdata1

9

Results

GraphicLinearAlgorithmO(n)

GraphicAlgorithmO(nlogn)

GraphicQuadraticAlgorithmO(n2)

GraphicCubicAlgorithmO(n3)

GraphicResume

Resume

• Linearalgorithmisstableforanysizeofdata• SimplifyyourcomplexityifyoufoundQuadraticandCubicalgorithminyourcode.Avoidnestedlooping.• Choosetherightdatastructurefortherightoperation.