Algorithm Analysis (2)


0. Complexity Classes


1. Doubling Ratio Experiments -- What Happens if N is Doubled


2. Complexity of operations on Array-based lists and Linked lists

Java Collection	    ArrayList		LinkedList
======================================================

add(item) --------- constant/linear*    constant

add(idx, item) ---- linear (**)         linear

contains(item) ---- linear              linear

remove(item) ------ linear              linear

remove(idx, item)-- linear              linear

get(idx) ---------- constant            linear

set(idx,item) ----- constant            linear

iterator

    hasNext-------- constant            constant

    next ---------- constant            constant

    remove -------- linear              constant

*: Adding to the end of an arraylist is linear when the array is full and needs to be expanded

3. Timing Java Methods


4. Example problems

  1. BinarySearch -- O(lgn)

  2. "2-Sum problem"

  3. "3-Sum problem"