Personal notes for programming


  • To find if a connected graph is cyclic simple do a bfs and check if the number of visited adjacent nodes for ant node are greater than 2 then the graph contains cycle.


  • Some important values-2^10 approx 10^3 ,2^20 approx 10^6


  • Important modular arithmetic formulas- 

(A + B) % P = (A % P + B % P) % P
(A * B) % P = (A % P * B % P) % P
(a - b) mod p = ((a mod p - b mod p) + p) mod p

(a / b) mod p = ((a mod p) * (b^(-1) mod p)) mod p
p = primeb^(-1) mod p = b^(p - 2) mod p

  • Combinatorics imp points:-
consider the set {1, 2, 3}. There are 23=8 total subsets (of all sizes), which are

{, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}}
Combinations count the subsets of a particular size (n choose r counts the number of r-element subsets of an n-element set). In our running example consider how many subsets of size 2 there are:


(Imp see that only {1,2} is there not {2,1})


To count undirected loopless graphs with no repeated edges, first count possible edges. As Andre counts, there are  such edges. One by one, each edge is either included or excluded. So this gives possible graphs.
If loopless graphs with no repeated edges are directed, each pair of vertices a<b provides  possibilities for a (potentially absent) edge. So we have 3 choices (a,b) (b,a) and not present.

Comments

Popular Posts