spcs:summer2014:teaching_notes

This shows you the differences between two versions of the page.

— |
spcs:summer2014:teaching_notes [2014/06/18 19:42] (current) ffpaladin created |
||
---|---|---|---|

Line 1: | Line 1: | ||

+ | |||

+ | ====== Software Engineering ====== | ||

+ | |||

+ | |||

+ | ===== Math ===== | ||

+ | |||

+ | Prime Numbers | ||

+ | * every positive integer can be a product of primes. | ||

+ | * prime factorization | ||

+ | * Sieve of Eratosthenes | ||

+ | |||

+ | Permutations/Combinations | ||

+ | * Permutations - order matters | ||

+ | * with repetition: lock | ||

+ | * n^k | ||

+ | * without repetition: rainbow | ||

+ | * n!/(n-r)! | ||

+ | * Combinations - order doesn't matter | ||

+ | * with repetition: icecream | ||

+ | * (n r) | ||

+ | * n!/r!(n-r!) | ||

+ | * without repetition: fruit salad | ||

+ | * (n+n-r r) | ||

+ | |||

+ | Bit Manipulation | ||

+ | * ^ XOR, ~ boolean NOT | ||

+ | * 0110 + 0110 is the same as 0110 * 2, shifting 0110 left by 1. | ||

+ | * Multiplying by 2^2 just shifts a number by n | ||

+ | * a ^ (~a) is all 1's | ||

+ | * bit shifting | ||

+ | * arithmetic shift | ||

+ | * logical shift | ||

+ | * circular rotate | ||

+ | * Uses | ||

+ | * boolean isPalindrome(int x) | ||

+ | * get bit - num & (1 << i) != 0 | ||

+ | * set bit - num | (1 << i) | ||

+ | * clear bit - num & mask, mask = ~(1 << i) | ||

+ | * clear from MSB or 0 | ||

+ | * powers of 2: http://en.wikipedia.org/wiki/Power_of_two | ||

+ | |||

+ | |||

+ | * In Java, all integer types are signed, and the "<<" and ">>" operators perform arithmetic shifts. | ||

+ | * Java adds the operator ">>>" to perform logical right shifts, | ||

+ | * but because the logical and arithmetic left-shift operations are identical, there is no "<<<" operator in Java. | ||

+ | |||

+ | |||

+ | ===== Basic Data Structures ===== | ||

+ | * Strings | ||

+ | * [[http://pastebin.com/1FAaQhTp|has repeats?]] | ||

+ | * Arrays | ||

+ | * Linked Lists | ||

+ | |||

+ | <code java> | ||

+ | |||

+ | Node deleteNode(Node head, int d) { | ||

+ | Node n = head | ||

+ | |||

+ | if (n.data == d) { | ||

+ | return head.next; // moved head | ||

+ | } | ||

+ | |||

+ | while (n.next != null) { | ||

+ | if (n.next.data == d) { | ||

+ | n.next = n.next.next; | ||

+ | return head; // head didn't change | ||

+ | } | ||

+ | n = n.next; | ||

+ | } | ||

+ | return head; | ||

+ | } | ||

+ | |||

+ | </code> | ||

+ | |||

+ | |||

+ | ===== Advanced Data Structures ===== | ||

+ | |||

+ | * Stacks | ||

+ | * Queues | ||

+ | * Trees | ||

+ | * balanced or unbalanced, full and complete | ||

+ | * Tries - Unlike a binary search tree, no node in the tree stores the key associated with that node; instead, its position in the tree defines the key with which it is associated. All the descendants of a node have a common prefix of the string associated with that node, and the root is associated with the empty string. | ||

+ | * Graphs - http://pastebin.com/MtJQDqVZ | ||

+ | * AdjacencyList | ||

+ | * Matrix | ||

+ | * HashMap | ||

+ | |||

+ | <code java> | ||

+ | public HashMap<Integer, Student> buildMap(Student[] students) { | ||

+ | HashMap<Integer, Student> map = name HashMap<Integer, Student>(); | ||

+ | for (Student s : students) map.put(s.getId(),s); | ||

+ | return map; | ||

+ | } | ||

+ | </code>If you're only interested in the keys, you can iterate through the keySet() of the map: | ||

+ | |||

+ | <code java> | ||

+ | Map<String, Object> map = ...; | ||

+ | |||

+ | for (String key : map.keySet()) { | ||

+ | // ... | ||

+ | } | ||

+ | </code> | ||

+ | |||

+ | If you only need the values, use values(): | ||

+ | |||

+ | <code java> | ||

+ | for (Object value : map.values()) { | ||

+ | // ... | ||

+ | } | ||

+ | </code> | ||

+ | |||

+ | Finally, if you want both the key and value, use entrySet(): | ||

+ | |||

+ | <code java> | ||

+ | for (Map.Entry<String, Object> entry : map.entrySet()) { | ||

+ | String key = entry.getKey(); | ||

+ | Object value = entry.getValue(); | ||

+ | // ... | ||

+ | } | ||

+ | </code> | ||

+ | |||

+ | One caveat: if you want to remove items mid-iteration, you'll need to do so via an Iterator (see karim79's answer). However, changing item values is OK (see Map.Entry). | ||

+ | |||

+ | |||

+ | ===== Algorithms ===== | ||

+ | |||

+ | * Recursion - take at least O(n) space, where n is depth of recursive call. | ||

+ | * dynamic programming caches results | ||

+ | * Sorting | ||

+ | * Searching | ||

+ | * Big O - http://bigocheatsheet.com/ | ||

+ | * P - Polynomial Time | ||

+ | * NP - Verification is P | ||

+ | * NPComplete is NPHard that can be reduced to NP problem (for verification only) | ||

+ | * NPHard - Shortest traveling sales person | ||

+ | |||

+ | ===== Design ===== | ||

+ | |||

+ | 4 principles of OOP | ||

+ | * Data Abstraction | ||

+ | * Encapsulation | ||

+ | * Inheritance | ||

+ | * Polymorphism | ||

+ | |||

+ | * Object-Oriented | ||

+ | * factory - cardgame | ||

+ | * singleton - restaurant | ||

+ | * "does it make sense to call this method, even if no Obj has been constructed yet?" If so, it should definitely be static. | ||

+ | * System Design | ||

+ | * Memory Limits | ||

+ | * order of appearance, hash value, random/arbitrarily | ||

+ | * http://www.cs.umd.edu/class/sum2003/cmsc311/Notes/Data/endian.html | ||

+ | * Testing | ||

+ | * who | ||

+ | * what cases | ||

+ | * bounds/environmental | ||

+ | * failure conditions | ||

+ | * how to test | ||

+ | * manual/automated | ||

+ | * black/whitebox | ||

+ | * values | ||

+ | * normal | ||

+ | * extremes | ||

+ | * nulls | ||

+ | * strange | ||

+ | * troubleshooting | ||

+ | * Design Patterns - http://en.wikipedia.org/wiki/Software_design_pattern | ||

+ | |||

+ | |||

+ | [[teaching notes]] | ||

+ | |||

/soe/sherol/.html/teaching/data/pages/spcs/summer2014/teaching_notes.txt · Last modified: 2014/06/18 19:42 by ffpaladin