Search
Create
Log in
Sign up
Log in
Sign up
CS Set 1
STUDY
Flashcards
Learn
Write
Spell
Test
PLAY
Match
Gravity
Terms in this set (11)
Adjacency List
-Array of linked lists
-Can also store weighted edges
-Space = O(|V| + |E|) -- max O(V^2)
-Add edge in constant time (to front of list)
-O(V) to query edge (or get adjacent edge)
Adjacency Matrix
-2D Array
-if adj[i][j] == 1, edge from i to j (can be weighted = w)
-Query, addition, and removal at O(1) for edges
-Has to be symmetric
-O(V^2) space
-Adding vertex = O(V^2) -- resize and copy
Graph as Objects and References
-Space: Average = O(V + E) --- Worst = O(V^2) space
-O(n) access time
-need a way to keep track of all nodes (array of V pointers)
ELO Scoring
-Win -> Rating = Old + 10 x [1 - 1 / (1 + 10 ^ (yours - opps)/400))]
-Lose -> Rating = Old - 10 x [1 - 1 / (1 + 19 ^ (opps - yours)/400))]
*10 = constant... I used the one for HoN with a starting ELO of 1500
Is It Prime?
if(x < 2) false;
for(int i = 2; i < Math.sqrt(x); i++)
{
if (x % i == 0)
return false;
}
return true;
List of Primes (Sieve of Eratosthenes)
-boolean[] = new Boolean[max + 1]
-set all flags to true except 1 and 0
-while(prime <= math.sqrt(max)), prime starts @ 2
--Cross of all prime*prime + prime multiples
--Next prime = increment until next true flag
Probability of A & B
P(A & B) = P(B given A) * P(A)
Probability of A or B
P(A or B) = P(A) + P(B) - P(A & B)
Probability of Independent Events
-P(A & B) = P(A) * P(B)
Probability of Mutual Exclusion
*If one event happens, then the other cannot happen
-P(A or B) = P(A) + P(B)
Math # of Permutations of a String
total letters!
-----------------------------------
(# A's)! x (# B's)! x .... (#Z's)!
;