Wangling I'm Wang Ling. I'm wangling you.

Posts Tagged ‘algorithms’

Greatest Common Divisor & Least Common Multiple

Euclid’s GCD Algorithm: Fundamentals: gcd(N, M) = gcd(M, N mod M) gcd(N, 0) = N Implementation in C: int Euclid_gcd_recursive(int a, int b) { if (b == 0) return a; return Euclid_gcd_recursive(b, a % b); } int Euclid_gcd_iterative(int a, int b) { int t; while (b) { a = b; b = t % b; [...]

Classic Sorting Algorithms

Comparison Sort Selection Sort advantages: least data movement (N – 1 exchanges). disadvantages: does not make good use of the initial order of the keys, and one pass through the keys does not give any hint to the next pass. stability: stable. operations: N2/2 comparisons, N – 1 exchanges. space: in-space sort, O(N). implementation in [...]