1 / 16

Big O and Algorithms (Part 2)

Big O and Algorithms (Part 2). by Samuel Monnier http ://algorithmic-worlds.net/. Discrete Structures (CS 173) Madhsuudan Parthasarathy, University of Illinois. Last class. Big-O Model algorithm efficiency as a function of the parameter size

saki
Télécharger la présentation

Big O and Algorithms (Part 2)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Big O and Algorithms (Part 2) by Samuel Monnier http://algorithmic-worlds.net/ Discrete Structures (CS 173) Madhsuudan Parthasarathy, University of Illinois

  2. Last class • Big-O • Model algorithm efficiency as a function of the parameter size • Asymptotic analysis: how does it perform for large inputs? • Keep only dominant terms, ignoring coefficients • Applies to runtimes or memory usage or any other resources

  3. This class • Midterm review: induction form and strategies • Analysis of algorithm complexity • For loops • While loops • Recursion

  4. Algorithms • Practice analyzing runtime based on pseudocode

  5. Key concept: instructions in the loops dominate

  6. Key concept: runtime can be in terms of multiple input parameters

  7. Key concept: n/2 recursion http://www.youtube.com/watch?v=XaqR3G_NVoo

  8. Reachability algorithm reachable(G: graph; s,t: nodes in G) if (s=t) return true; Unmark all nodes in G. M=emptylist Mark node s and add it to M while (M is not empty) { p=pop(M) for every node q in neighbor(p) in G if q=t return true; else if q is not marked, mark q and add it to M } return false

  9. Binary search Searching a sorted array A[1..n] binary_search(int A[],int key,intimin,intimax){ if(imax<imin)return -1; else{ intimid= midpoint(imin,imax); if(A[imid]> key)returnbinsearch(A, key,imin,mid-1); elseif(A[imid]< key) binsearch(A, key, imid+1,imax); elsereturnimid; } }

  10. Binary search

  11. http://introcs.cs.princeton.edu/java/23recursion/hanoi/

  12. Multiplying large numbers Naïve divide and conquer:

  13. Multiplying large numbers More clever divide and conquer (Karatsuba)

  14. Thursday • We won’t do NP next lecture. • We will do advanced recursion/induction instead • No reading for Thu.

More Related