Published on

CS 3500 Day 14

Authors
  • avatar
    Name
    Jacob Aronoff
    Twitter

Object Oriented Design

Today we're talking more about big O, and efficiency.

T(n)NameExample
O(1)ConstantAdding to the front of a linked list
O(n)LinearAccessing each element of an array
O(n^2)QuadraticChecking duplicates in a list
O(n^3)CubicMatrix multiplication
O(n^d)PolynomialA bunch of random things
O(log(n))LogarithmicBinary search
O(nlog(n))LinearithmicMergesort, heapsort, quicksort

A representation:

bigo

Now we're talking about the traveling salesman problem.

| Data structure | Add to front | Add to back | Add in general | Find | Remove | | --------------- | :----------: | :---------: | :------------: | :-------: | :-------: | ---- | | List(ArrayList) | O(n) | O(1)^ | O(n) | O(n) | O(log(n)) | O(n) | | LinkedList | O(1) | O(1) | O(n) | O(n) | Linear | | TreeSet | N/A | N/A | O(log(n)) | O(log(n)) | O(log(n)) | | TreeMap | N/A | N/A | O(log(n)) | O(log(n)) | O(log(n)) | | HashMap | N/A | N/A | O(1)** | O(1)** | O(1)** | | HashSet | N/A | N/A | O(1)** | O(1)** | O(1)** |

^ Amortized ** Only when the hashcode function has to disperse properly among the buckets