1 / 14

CS151 Lab 2

CS151 Lab 2. 9/15/2005. How to Turn In Assignments. Do not use the submission instructions associated with the test environment. These call for you to store your .java files in an encrypted .jar file and leave them in a public directory in your account. Too much trouble.

howell
Download Presentation

CS151 Lab 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. CS151 Lab 2 9/15/2005

  2. How to Turn In Assignments • Do not use the submission instructions associated with the test environment. • These call for you to store your .java files in an encrypted .jar file and leave them in a public directory in your account. • Too much trouble. • Just email them to me. • Source code (.java files) • Probably best to .zip or .tgz them with other soft-copy files you send. • Both hard and soft copies.

  3. Asymptotic Growth Rate(Order Notation) Definitions • f(n) = O(g(n)): • There exist positive constants c and N: • If n > N, f(n) < cg(n) • ie: for large n, f grows no faster than g.

  4. Asymptotic Growth Rate(Order Notation) Definitions • f(n) = W(g(n)): • There exist positive constants c and N: • If n > N, f(n) > cg(n) • ie: for large n, f grows at least as fast (no slower than) than g.

  5. Asymptotic Growth Rate(Order Notation) Definitions • f(n) = Q(g(n)): • f(n) = O(g(n)) and f(n) = W(g(n)) • There exist positive constants c1 and N1: • If n > N, f(n) < cg(n) • ie: for large n, f grows no faster than g. • There exist positive constants c2 and N2: • If n > N, f(n) > cg(n) • ie: for large n, f grows at least as fast than g. • f and g differ by a constant factor.

  6. Asymptotic Growth Rate • In this class, we will generally not differentiate between f and g if f(n) = Q(g(n)). • Does this makes sense? • n2 + n + 10000 = n2 – 3? • en + n1000 = en+ n2?

  7. Asymptotic Growth Rate • We rank or rate algorithms by their complexity. • Time complexity • Space complexity • Computers are fast... • Even really difficult (time-consuming) operations don’t take a lot of time on a modern computer on small input sets. • Suppose it takes 100ns to do it the right way and 1s to do it a wrong way. • You’ll still never notice. • But for a much larger-size input... • The same 2 algorithms would take 100s and 1 billion s! • You would definitely notice this. • At this scale, the large term of the function dominates.

  8. Asymptotic Growth Rate • At these scales, one term of the function tends to dominate.

  9. Asymptotic Growth Rate • Lets look at the functions in in-class exercise 1.7. • f(x) = x • f(x) = x2 • f(x) = log2(x) • f(x) = xlog2(x) • f(x) = 2x • f(x) = ex

  10. In-class Exercise 1.6 • Go ahead and implement the “SelectionSort” algorithm • Use the files in the class notes • This does not use the test environment. • But you should be able to use the same function you write today (renamed) for the homework.

  11. SelectionSort data[0] min Unsorted Data min data[0] Find Minimum Swap Now all but the top is unsorted

  12. SelectionSort • So: • Let x = 0, y = (size of data) • 1: Find minimum in data[x..y] • 2: Swap the minimum with data[x] • 3: x += 1 • 4: Go to step 1 unless x = y

  13. In-class Exercise 1.8 • Let’s try and prove: • loga(xy) = loga(x) + loga(y). • Don’t cheat and look at the solution.

  14. Questions about Exercise 1

More Related