Introduction

1. Why Study Algorithms

  a)  important for all other branches of computer science
  b)  plays a key role in modern technological innovation
  c)  provides novel “lens” on processes outside of computer science and technology
  d)  challenging (i.e., good for the brain!)
  e)  fun

 

2. A recursive algorithm for multiplication of two n-digits numbers

  x = a* 10^n/2 + b ; y=c*10^n/2 + d

  x*y = ac*10^n + (bc + ad) * 10^1/2 + bd

Idea: recusively compute ac, bc, ad, bd until one digit multiplication.

 

3. Karatsuba Multiplication

 x*y = ac*10^n + (bc + ad) * 10^1/2 + bd

(bc+ad) = (a+b) * (c+d) - ac - bd

 

Idea: only need to recursively compute ac, bd, (a+b) * (c+d) -- 3 recursive multiplications

 

4. Course Topics

  a)  Vocabulary for design and analysis of algorithms
  b)  Divide and conquer algorithm design paradigm
  c)  Randomization in algorithm design
  d)  Primitives for reasoning about graphs
  e)  Use and implementation of data structures

5. References:

  a)  Kleinberg/Tardos, Algorithm Design, 2005.
  b)  Dasgupta/Papadimitriou/Vazirani, Algorithms, 2006.
  c)  Cormen/Leiserson/Rivest/Stein, Introduction to Algorithms, 2009 (3rd edition).
  d)  Mehlhorn/Sanders, Data Structures and Algorithms: The Basic Toolbox, 2008.

6. Merge Sort:

  a) recursively sort 1st half of the input array

  b) recursively sort 2rd half of the input array

  c)  merge two sorted sublists into one

 

7. Pseudocode for Merge:

 

C = output [length = n]
A = 1st sorted array [n/2]
B = 2nd sorted array [n/2]

i = 1
j = 1

for k = 1 to n
    if A(i) < B(j)
        C(k) = A(i)
        i++
    else [B(j) < A(i)]
        C(k) = B(j)
        j++
end

 

8. Running Time of Merge for m elements : 4m (compare, assingment, increment of i/j, increment of k) + 2 (init of i&j ) <= 6m ( m>=1)

 

9. Running Time of Merge Sort :

  For every input arry of n numbers, Merge Sort produces a sorted output array and uses at most 6nlogn+6n operations. ( logn + 1 level of recursion tree and each level take 6n )

 

10. Guiding Principle:

  a) worst-case analysis over running time

  b) won't play much attention to constant factors, lower-order terms

  c) asymptotic analysis: focus on running time fro large input size n

 

11. fast algorithm = worst-case running time grows slowly with input size. Usually want as close to linear(O(n)) as possible.

 

你可能感兴趣的:(Algorithm,Merge sort)