Lab 8

Practical Asymptotic Analysis + TreeMaps

Announcements

  1. Lab 8 due Friday 3/11
  2. HW 6 due Tuesday 3/29 (after break)

Your mental health and wellbeing are more important than this course.

Academic + Mental Health Resources

CAPS

  • All students will continue to have access to mental health services at UHS regardless of insurance and UHS counseling visits are still free of charge.
  • CAPS has a lot of resources:
  • For students that want to see a counselor, the majority of appointments are now offered the same day.
  • Students are seen for their top-of-mind concerns and given resources, whether at an initial or returning counseling visit.

How do we measure the "speed" of programs?

Algorithmic analysis: express the "cost" of a program (time, space, etc.) as a function of the inputs.

We can use asymptotics to compare these cost functions to each other.

Empirical analysis: use a clock (or a relevant tool) to measure the cost on different inputs.

Depending on how the program is run (computer power, other programs, etc.), can vary!

Program to time sorting code: timer.SortTiming

Amortized Runtime

Sometimes, we measure costs of a single call to a function. Other times, we're concerned with the average runtime, because the worst-case doesn't occur often. (Lecture 17)

Example: dynamic resizing arrays

Program to time amortization: timer.AmoritzationTiming

TreeMap

Whiteboard BST review during lab

compareTo

            
              class A implements Comparable<A> {
                @Override
                public int compareTo(A other) { ... }
              }
            
          
            
              A a1 = new A();
              A a2 = new A();
              if (a1.compareTo(a2) < 0) {
                // a1 < a2
              } else if (a1.compareTo(a2) > 0) {
                // a1 > a2
              } else if (a1.compareTo(a2) == 0) {
                // a1 == a2
              }