Docsity

Complexity - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Partial preview of the text

Download Complexity - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

What is complexity^ ^ Consider a sorting program that runs on a data set^ ^ Try multiplying the size of the data set and continue toexperiment^ ^ What happens??^ ^ Demo

What Factors Determine theruntime of a program?

Among all those factors^ ^ Size of the data set is one factor that we can analyze^ ^ That is, we can describe the runtime as a function of n(size of the data set)^ ^ Example:^ ^ for (int i=0; i<n ; i++)^ ^ Do_something^ ^ for (int i=0; i<n ; i=i/2)^ ^ Do_something

Definition of Big O^ ^ Formal Definition:

f(n) = O(g(n)) means there are positive constants c and k, such that 0 ≤ f(n) ≤ cg(n)for all n ≥ k. The values of c and k must be fixed for thefunction f and must not depend on n. 

Complexity of basic algorithms^ ^ Finding an element in an unsorted array of size n^ ^ Finding an element in a sorted array of size n^ ^ Reversing an array of size n^ ^ Sorting an array of size n

Determining big O

Final Thoughts^ ^ Asymptotic analysis is a way to determine theperformance of an algorithm^ ^ However, it is not the only factor that affectsperformance^ ^ For the most part other factors also have a significantimpact on performance of systems^ ^ Network latency^ ^ Language efficiency^ ^ Data Structures^ ^ Many many other factors