r inkulu http iitg ac in rinkulu
play

R. Inkulu http://www.iitg.ac.in/rinkulu/ 1 only very essential - PowerPoint PPT Presentation

Asymptotic complexity 1 R. Inkulu http://www.iitg.ac.in/rinkulu/ 1 only very essential notions are covered (Asymptotic complexity) 1 / 7 RAM model of computation The machine independent abstract model is useful in measuring the run time of


  1. Asymptotic complexity 1 R. Inkulu http://www.iitg.ac.in/rinkulu/ 1 only very essential notions are covered (Asymptotic complexity) 1 / 7

  2. RAM model of computation • The machine independent abstract model is useful in measuring the run time of an algorithm by counting up the number of steps it takes. • The Random Access Machine (RAM) model of computation is the commonly used abstract model: * each primitive operation takes constant time (ex. + , − , ∗ , /, || , <, == , = etc.,) * memory access takes constant time (Asymptotic complexity) 2 / 7

  3. Input, time and space complexities • The time and space complexities are expressed in terms of the size of the input ( input complexity ); asymptotic analysis assumes that the input is large in size • The asymptotic time complexity is the asymptotic number of units of time taken by a program on RAM model • The asymptotic space complexity is the asymptotic number of bytes used by the program the asymptotic auxiliary space (a.k.a. work space) complexity is the asymptotic number of bytes used by the program excluding the input space complexity (Asymptotic complexity) 3 / 7

  4. O () notation For any given input size n , how long an algorithm takes asymptotically ”at most” is denoted with O () 2 : ignores constants and non-dominating terms from an expression. Examples - • summing all the n numbers takes O ( n ) time and O (1) space • given a pointer to an array containing n integers, summing the first and last numbers takes O (1) time and O (1) space • for (int i=0; i<n; i++) for (int j=0; j<m; j++) sum += A[i][j]; execution of the above nested loop is said to take O ( nm ) time and O (1) space 2 precise definition of O () notation is avoided (Asymptotic complexity) 4 / 7

  5. Comparing algorithms based on the asymptotic complexity cn! n resource c2 2 cn 2 cn lg n (logarithmic) cn c lg n c n (linear) (Asymptotic complexity) 5 / 7

  6. Time and space resources • space reource is reusable whereas time is not • space used by an algorithm is less than or equal to the time spent (excluding the input complexity) • time-space tradeoffs (Asymptotic complexity) 6 / 7

  7. Worst-case asymptotic complexity For every fixed asymptotically large n , if an algorithm A computes a solution to problem P for any input of size n in (resp. using) O ( f ( n )) time (resp. space), then O ( f ( n )) is said to be the tight 3 worst-case asymptotic upper bound on the time (resp. space) complexity 4 of A . • Given a pointer to an array containing n integers in sorted order, binary search takes in worst-case O (lg n ) time and O (1) space. • Bubble sort: O ( n 2 ) worst-case time and O (1) worst-case space; takes O ( n ) time in the best-case 3 O ( n ) time algorithm takes O ( n 3 ) as well but the latter is not a tight bound 4 analogously, best-case and average-case resource complexities are defined (Asymptotic complexity) 7 / 7

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend