1. Data Structure: an arrangement of data in a computer's memory or hard disk
  2. Algorithm: The way of manipulating the data stored in the memory
  3. fencepost and initial test are bros
  4. Reference Semantics
    1. !!!!Basics
      1. Value Semantics (Value Types)
        1. primitive
      2. Reference Semantics (Reference Types)
        1. stores address
        2. objects
        3. !!Why
          1. Efficiency
          2. memory
          3. Share
          4. allow diff part share an obj
    2. Multiple Objects
      1. list1=list2;
        1. both refer to a same location
      2. pass list1 to data in method
        1. both refer to a same location
      3. we copy the address, so when modifying it, we do not modify the copy as primitive type. we modify the value in this reference.
    3. null
      1. no object
  5. Advanced Array Techniques
    1. Shifting Values in an Array
      1. left shifting
        1. local variable
        2. avoid off-by-one
      2. right shifting
        1. local variable
        2. avoid over write
        3. loop in reverse order
    2. Arrays of Objects
      1. two-step process
      2. ???kan bu dong
    3. Command-Line Arguments
      1. invoke this when java init
      2. ??? kan bu dong
    4. Nested Loop Algorithms
      1. 1. sequence; after; length-1
      2. 2. start after outer loop; j=i+1
  6. Multidimensional Arrays
    1. basics
      1. Multidimensional Array
    2. Rectangular 2D Arrays
      1. double[][] temps = new double [rows][columns]
      2. grid.length; grid[i].length
      3. System.out.println(Arrays.deepToString(temps));
      4. row----column||||
    3. Jagged Arrays
      1. no. of cols varies
      2. int[][] jagged = new int[3][];
      3. jagged[0] = new int[2];
      4. jagged[1] = new int[4];
      5. jagged[2] = new int[3];
      6. Pascal's Triangle
  7. Array-Traversal Algorithms
    1. Printing an array
      1. Array.toString(<array>);
      2. for-each
      3. fencepost traversal loop + init test
    2. Searching and Replacing
      1. return -1; do not find in the list
    3. Testing for Equality
      1. Arrays.equals(l1, l2);
      2. Common pattern for equals:
      3. 1. test all of the ways that cause false
      4. 2. return true at the very end
    4. Reversing Arrays
    5. String Traversal Algorithms
      1. for(int i=0; i<<string>.length(); i++) {<do sth with string.charAt(i)>}
  8. Array Basics
    1. basics
      1. Array
        1. indexed
        2. multiple values(elements) with same type
      2. Index
      3. Zero-based indexing
    2. Constructing and Traversing an Array
      1. Auto initialization
      2. REFERENCE
      3. Array Traversal
        1. for loop
        2. off-by-one error
        3. standard pattern
    3. Accessing an Array
      1. Buffer overruns
    4. fast random access
    5. code
      1. constructor: <element type>[] name = new <element type>[<length>]
      2. <array>.length
        1. last value is .length-1
        2. middle: .length/2
    6. Arrays and Methods
      1. The value passed to method can be changed
      2. do not need to return an array
      3. return an array is better for understanding
    7. for-each loop
      1. for (<type> <name> : <array>) {}
        1. simply examine each value
        2. changing <name> does not change array
        3. not convenient most times
      2. standard pattern
    8. initialize Arrays
      1. <element type>[] <name> = {<value>, <value>...};
        1. this way, java counts the no. and construct the right size
        2. only 'array' and 'string' can construct obj without new
    9. The array class
      1. import java.util.*;(package)
      2. limitations
        1. cannot change the size in the middle of exe
          1. larger array? construct a new one and copy the old one
          2. int[] newData = Arrays.copyOf(data, 2 * data.length);
          3. copy portion?
          4. Array.copyOfRange
        2. cannot print array
          1. Arrays.toString(<array>)
        3. cannot using == compare arrays
          1. Array.equals(d1,d2);