SlideShare a Scribd company logo
Introduction to Algorithms
                           6.046J/18.401J
                                     LECTURE 3
                                     Divide and Conquer
                                     • Binary search
                                     • Powering a number
                                     • Fibonacci numbers
                                     • Matrix multiplication
                                     • Strassen’s algorithm
                                     • VLSI tree layout
                     Prof. Erik D. Demaine
September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.1
The divide-and-conquer
         design paradigm
            1. Divide the problem (instance)
               into subproblems.
            2. Conquer the subproblems by
               solving them recursively.
            3. Combine subproblem solutions.




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.2
Merge sort
   1. Divide: Trivial.
   2. Conquer: Recursively sort 2 subarrays.
   3. Combine: Linear-time merge.




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.3
Merge sort
   1. Divide: Trivial.
   2. Conquer: Recursively sort 2 subarrays.
   3. Combine: Linear-time merge.
                       T(n) = 2 T(n/2) + Θ(n)

  # subproblems                                                   work dividing
                                                                  and combining
                       subproblem size

September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.4
Master theorem (reprise)
                       T(n) = a T(n/b) + f (n)
  CASE 1: f (n) = O(nlogba – ε), constant ε > 0
    ⇒ T(n) = Θ(nlogba) .
  CASE 2: f (n) = Θ(nlogba lgkn), constant k ≥ 0
    ⇒ T(n) = Θ(nlogba lgk+1n) .
  CASE 3: f (n) = Ω(nlogba + ε ), constant ε > 0,
  and regularity condition
    ⇒ T(n) = Θ( f (n)) .


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.5
Master theorem (reprise)
                       T(n) = a T(n/b) + f (n)
  CASE 1: f (n) = O(nlogba – ε), constant ε > 0
    ⇒ T(n) = Θ(nlogba) .
  CASE 2: f (n) = Θ(nlogba lgkn), constant k ≥ 0
    ⇒ T(n) = Θ(nlogba lgk+1n) .
  CASE 3: f (n) = Ω(nlogba + ε ), constant ε > 0,
  and regularity condition
    ⇒ T(n) = Θ( f (n)) .
Merge sort: a = 2, b = 2 ⇒ nlogba = nlog22 = n
  ⇒ CASE 2 (k = 0) ⇒ T(n) = Θ(n lg n) .
September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.6
Binary search
  Find an element in a sorted array:
  1. Divide: Check middle element.
  2. Conquer: Recursively search 1 subarray.
  3. Combine: Trivial.




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.7
Binary search
  Find an element in a sorted array:
  1. Divide: Check middle element.
  2. Conquer: Recursively search 1 subarray.
  3. Combine: Trivial.
  Example: Find 9
             3       5          7          8         9         12         15


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.8
Binary search
  Find an element in a sorted array:
  1. Divide: Check middle element.
  2. Conquer: Recursively search 1 subarray.
  3. Combine: Trivial.
  Example: Find 9
             3       5          7          8         9         12         15


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.9
Binary search
  Find an element in a sorted array:
  1. Divide: Check middle element.
  2. Conquer: Recursively search 1 subarray.
  3. Combine: Trivial.
  Example: Find 9
             3       5          7          8         9         12         15


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.10
Binary search
  Find an element in a sorted array:
  1. Divide: Check middle element.
  2. Conquer: Recursively search 1 subarray.
  3. Combine: Trivial.
  Example: Find 9
             3       5          7          8         9         12         15


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.11
Binary search
  Find an element in a sorted array:
  1. Divide: Check middle element.
  2. Conquer: Recursively search 1 subarray.
  3. Combine: Trivial.
  Example: Find 9
             3       5          7          8         9         12         15


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.12
Binary search
  Find an element in a sorted array:
  1. Divide: Check middle element.
  2. Conquer: Recursively search 1 subarray.
  3. Combine: Trivial.
  Example: Find 9
             3       5          7          8         9         12         15


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.13
Recurrence for binary search
                     T(n) = 1 T(n/2) + Θ(1)

# subproblems                                                 work dividing
                                                              and combining
                     subproblem size




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.14
Recurrence for binary search
                     T(n) = 1 T(n/2) + Θ(1)

# subproblems                                                 work dividing
                                                              and combining
                     subproblem size


      nlogba = nlog21 = n0 = 1 ⇒ CASE 2 (k = 0)
         ⇒ T(n) = Θ(lg n) .

September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.15
Powering a number
Problem: Compute a n, where n ∈ N.
Naive algorithm: Θ(n).




 September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.16
Powering a number
Problem: Compute a n, where n ∈ N.
Naive algorithm: Θ(n).
Divide-and-conquer algorithm:
                      a n/2 ⋅ a n/2                           if n is even;
        an    =
                      a (n–1)/2 ⋅ a (n–1)/2 ⋅ a               if n is odd.



 September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.17
Powering a number
Problem: Compute a n, where n ∈ N.
Naive algorithm: Θ(n).
Divide-and-conquer algorithm:
                      a n/2 ⋅ a n/2                           if n is even;
        an    =
                      a (n–1)/2 ⋅ a (n–1)/2 ⋅ a               if n is odd.

     T(n) = T(n/2) + Θ(1) ⇒ T(n) = Θ(lg n) .

 September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.18
Fibonacci numbers
      Recursive definition:
                  0           if n = 0;
           Fn = 1             if n = 1;
                  Fn–1 + Fn–2 if n ≥ 2.
       0      1      1     2       3       5       8 13 21 34 L




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.19
Fibonacci numbers
      Recursive definition:
                  0           if n = 0;
           Fn = 1             if n = 1;
                  Fn–1 + Fn–2 if n ≥ 2.
       0      1      1     2       3       5       8 13 21 34 L
      Naive recursive algorithm: Ω(φ n)
      (exponential time), where φ = (1 + 5) / 2
      is the golden ratio.
September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.20
Computing Fibonacci
          numbers
Bottom-up:
• Compute F0, F1, F2, …, Fn in order, forming
  each number by summing the two previous.
• Running time: Θ(n).




 September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.21
Computing Fibonacci
          numbers
Bottom-up:
• Compute F0, F1, F2, …, Fn in order, forming
  each number by summing the two previous.
• Running time: Θ(n).
Naive recursive squaring:
   Fn = φ n/ 5 rounded to the nearest integer.
• Recursive squaring: Θ(lg n) time.
• This method is unreliable, since floating-point
  arithmetic is prone to round-off errors.
 September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.22
Recursive squaring
                                                                               n
                   ⎡ Fn +1                        Fn ⎤ ⎡1 1⎤
          Theorem: ⎢                                   ⎥ = ⎢1 0⎥ .
                   ⎣ Fn                          Fn −1 ⎦ ⎣     ⎦




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.23
Recursive squaring
                                                                               n
                   ⎡ Fn +1                        Fn ⎤ ⎡1 1⎤
          Theorem: ⎢                                   ⎥ = ⎢1 0⎥ .
                   ⎣ Fn                          Fn −1 ⎦ ⎣     ⎦
          Algorithm: Recursive squaring.
            Time = Θ(lg n) .




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.24
Recursive squaring
                                                                               n
                   ⎡ Fn +1                        Fn ⎤ ⎡1 1⎤
          Theorem: ⎢                                   ⎥ = ⎢1 0⎥ .
                   ⎣ Fn                          Fn −1 ⎦ ⎣     ⎦
          Algorithm: Recursive squaring.
            Time = Θ(lg n) .
         Proof of theorem. (Induction on n.)
                       ⎡ F2 F1 ⎤ ⎡1 1⎤ 1
         Base (n = 1): ⎢         =⎢       .
                       ⎣ F1 F0 ⎥ ⎣1 0⎥
                               ⎦        ⎦
September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.25
Recursive squaring
         Inductive step (n ≥ 2):
                                                       .
         ⎡ Fn +1       Fn ⎤ ⎡ Fn        Fn −1 ⎤ ⎡1 1⎤
         ⎢ F                ⎥ = ⎢F            ⎥ ⋅ ⎢1 0⎥
                      Fn −1 ⎦ ⎣ n −1 Fn − 2 ⎦ ⎣
         ⎣ n                                           ⎦
                                      n−1
                                ⎡1 1⎤       ⎡1 1⎤
                              =⎢    ⎥      ⋅⎢       ⎥.
                                ⎣1 0⎦       ⎣1 0⎦
                                      n
                                ⎡1 1⎤
                              =⎢
                                ⎣1 0⎥
                                    ⎦
September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.26
Matrix multiplication
Input: A = [aij], B = [bij].
                                                                i, j = 1, 2,… , n.
Output: C = [cij] = A⋅ B.
  ⎡ c11 c12          L c1n ⎤ ⎡ a11 a12             L a1n ⎤ ⎡ b11 b12             L b1n ⎤
  ⎢c c               L c2 n ⎥ ⎢a21 a22             L a2 n ⎥ ⎢b21 b22             L b2 n ⎥
  ⎢ 21 22                   ⎥=⎢                           ⎥⋅⎢                           ⎥
  ⎢ M M              O M ⎥ ⎢ M      M              O M ⎥ ⎢ M M                   O M ⎥
  ⎢c c               L cnn ⎥ ⎣ an1 an 2
                              ⎢                    L ann ⎥ ⎢bn1 bn 2             L bnn ⎥
  ⎣ n1 n 2                  ⎦                             ⎦ ⎣                           ⎦

                                             n
                                cij = ∑ aik ⋅ bkj
                                           k =1
September 14, 2005      Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson    L2.27
Standard algorithm
         for i ← 1 to n
            do for j ← 1 to n
                    do cij ← 0
                        for k ← 1 to n
                           do cij ← cij + aik⋅ bkj




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.28
Standard algorithm
         for i ← 1 to n
            do for j ← 1 to n
                    do cij ← 0
                        for k ← 1 to n
                           do cij ← cij + aik⋅ bkj


         Running time = Θ(n3)


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.29
Divide-and-conquer algorithm
IDEA:
n×n matrix = 2×2 matrix of (n/2)×(n/2) submatrices:
              ⎡r s ⎤ ⎡a b ⎤ ⎡ e f ⎤
              ⎢ t u ⎥ = ⎢c d ⎥ ⋅ ⎢ g h ⎥
              ⎣     ⎦ ⎣      ⎦ ⎣       ⎦
                              C        =        A        ⋅       B
r   = ae + bg
s   = af + bh                8 mults of (n/2)×(n/2) submatrices
t   = ce + dg                4 adds of (n/2)×(n/2) submatrices
u   = cf + dh
    September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.30
Divide-and-conquer algorithm
IDEA:
n×n matrix = 2×2 matrix of (n/2)×(n/2) submatrices:
              ⎡r s ⎤ ⎡a b ⎤ ⎡ e f ⎤
              ⎢ t u ⎥ = ⎢c d ⎥ ⋅ ⎢ g h ⎥
              ⎣     ⎦ ⎣      ⎦ ⎣       ⎦
                            C = A ⋅ B
r   = ae + bg             recursive
s   = af + bh              8 mults of (n/2)×(n/2) submatrices
                            ^
t   = ce + dh              4 adds of (n/2)×(n/2) submatrices
u   = cf + dg
    September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.31
Analysis of D&C algorithm
                     T(n) = 8 T(n/2) + Θ(n2)

# submatrices                                                 work adding
                                                              submatrices
                     submatrix size




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.32
Analysis of D&C algorithm
                     T(n) = 8 T(n/2) + Θ(n2)

# submatrices                                                 work adding
                                                              submatrices
                     submatrix size

nlogba = nlog28 = n3 ⇒ CASE 1 ⇒ T(n) = Θ(n3).



September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.33
Analysis of D&C algorithm
                     T(n) = 8 T(n/2) + Θ(n2)

# submatrices                                                 work adding
                                                              submatrices
                     submatrix size

nlogba = nlog28 = n3 ⇒ CASE 1 ⇒ T(n) = Θ(n3).

       No better than the ordinary algorithm.

September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.34
Strassen’s idea
• Multiply 2×2 matrices with only 7 recursive mults.




   September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.35
Strassen’s idea
• Multiply 2×2 matrices with only 7 recursive mults.
   P1 = a ⋅ ( f – h)
   P2 = (a + b) ⋅ h
   P3 = (c + d) ⋅ e
   P4 = d ⋅ (g – e)
   P5 = (a + d) ⋅ (e + h)
   P6 = (b – d) ⋅ (g + h)
   P7 = (a – c) ⋅ (e + f )

   September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.36
Strassen’s idea
• Multiply 2×2 matrices with only 7 recursive mults.
   P1 = a ⋅ ( f – h)                             r    = P5 + P4 – P2 + P6
   P2 = (a + b) ⋅ h                              s    = P1 + P2
   P3 = (c + d) ⋅ e                              t    = P3 + P4
   P4 = d ⋅ (g – e)                              u    = P5 + P1 – P3 – P7
   P5 = (a + d) ⋅ (e + h)
   P6 = (b – d) ⋅ (g + h)
   P7 = (a – c) ⋅ (e + f )

   September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.37
Strassen’s idea
• Multiply 2×2 matrices with only 7 recursive mults.
   P1 = a ⋅ ( f – h)                             r    = P5 + P4 – P2 + P6
   P2 = (a + b) ⋅ h                              s    = P1 + P2
   P3 = (c + d) ⋅ e                              t    = P3 + P4
   P4 = d ⋅ (g – e)                              u    = P5 + P1 – P3 – P7
   P5 = (a + d) ⋅ (e + h)
   P6 = (b – d) ⋅ (g + h)                         7 mults, 18 adds/subs.
                                                  7 mults, 18 adds/subs.
   P7 = (a – c) ⋅ (e + f )                        Note: No reliance on
                                                  Note: No reliance on
                                                  commutativity of mult!
                                                  commutativity of mult!
   September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.38
Strassen’s idea
• Multiply 2×2 matrices with only 7 recursive mults.
   P1 = a ⋅ ( f – h)                             r = P5 + P4 – P2 + P6
   P2 = (a + b) ⋅ h                                = (a + d) (e + h)
   P3 = (c + d) ⋅ e                                  + d (g – e) – (a + b) h
   P4 = d ⋅ (g – e)                                  + (b – d) (g + h)
   P5 = (a + d) ⋅ (e + h)                          = ae + ah + de + dh
   P6 = (b – d) ⋅ (g + h)                            + dg –de – ah – bh
   P7 = (a – c) ⋅ (e + f )                           + bg + bh – dg – dh
                                                   = ae + bg
   September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.39
Strassen’s algorithm
    1. Divide: Partition A and B into
       (n/2)×(n/2) submatrices. Form terms
       to be multiplied using + and – .
    2. Conquer: Perform 7 multiplications of
       (n/2)×(n/2) submatrices recursively.
    3. Combine: Form C using + and – on
       (n/2)×(n/2) submatrices.



September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.40
Strassen’s algorithm
    1. Divide: Partition A and B into
       (n/2)×(n/2) submatrices. Form terms
       to be multiplied using + and – .
    2. Conquer: Perform 7 multiplications of
       (n/2)×(n/2) submatrices recursively.
    3. Combine: Form C using + and – on
       (n/2)×(n/2) submatrices.

                     T(n) = 7 T(n/2) + Θ(n2)

September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.41
Analysis of Strassen
                     T(n) = 7 T(n/2) + Θ(n2)




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.42
Analysis of Strassen
                       T(n) = 7 T(n/2) + Θ(n2)
nlogba = nlog27 ≈ n2.81 ⇒ CASE 1 ⇒ T(n) = Θ(nlg 7).




  September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.43
Analysis of Strassen
                       T(n) = 7 T(n/2) + Θ(n2)
nlogba = nlog27 ≈ n2.81 ⇒ CASE 1 ⇒ T(n) = Θ(nlg 7).
The number 2.81 may not seem much smaller than
3, but because the difference is in the exponent, the
impact on running time is significant. In fact,
Strassen’s algorithm beats the ordinary algorithm
on today’s machines for n ≥ 32 or so.


  September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.44
Analysis of Strassen
                        T(n) = 7 T(n/2) + Θ(n2)
 nlogba = nlog27 ≈ n2.81 ⇒ CASE 1 ⇒ T(n) = Θ(nlg 7).
The number 2.81 may not seem much smaller than
3, but because the difference is in the exponent, the
impact on running time is significant. In fact,
Strassen’s algorithm beats the ordinary algorithm
on today’s machines for n ≥ 32 or so.
Best to date (of theoretical interest only): Θ(n2.376L).
   September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.45
VLSI layout
 Problem: Embed a complete binary tree
 with n leaves in a grid using minimal area.




September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.46
VLSI layout
   Problem: Embed a complete binary tree
   with n leaves in a grid using minimal area.
                                          W(n)

H(n)




  September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.47
VLSI layout
   Problem: Embed a complete binary tree
   with n leaves in a grid using minimal area.
                                          W(n)

H(n)


H(n) = H(n/2) + Θ(1)
     = Θ(lg n)

  September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.48
VLSI layout
   Problem: Embed a complete binary tree
   with n leaves in a grid using minimal area.
                                          W(n)

H(n)


H(n) = H(n/2) + Θ(1)                            W(n) = 2 W(n/2) + Θ(1)
     = Θ(lg n)                                       = Θ(n)

  September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.49
VLSI layout
   Problem: Embed a complete binary tree
   with n leaves in a grid using minimal area.
                                          W(n)

H(n)


H(n) = H(n/2) + Θ(1) W(n) = 2 W(n/2) + Θ(1)
     = Θ(lg n)               = Θ(n)
               Area = Θ(n lg n)
  September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.50
H-tree embedding
                        L(n)



L(n)




   September 14, 2005     Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.51
H-tree embedding
                        L(n)



L(n)




       L(n/4) Θ(1) L(n/4)
   September 14, 2005     Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.52
H-tree embedding
                        L(n)

                                                       L(n) = 2 L(n/4) + Θ(1)
                                                            = Θ( n )
L(n)

                                                       Area = Θ(n)


       L(n/4) Θ(1) L(n/4)
   September 14, 2005     Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.53
Conclusion

• Divide and conquer is just one of several
  powerful techniques for algorithm design.
• Divide-and-conquer algorithms can be
  analyzed using recurrences and the master
  method (so practice this math).
• The divide-and-conquer strategy often leads
  to efficient algorithms.


September 14, 2005   Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson   L2.54

More Related Content

What's hot

Stat matematika II (2)
Stat matematika II (2)Stat matematika II (2)
Stat matematika II (2)
jayamartha
 
Rpl 012 - perancangan berorientasi objek
Rpl   012 - perancangan berorientasi objekRpl   012 - perancangan berorientasi objek
Rpl 012 - perancangan berorientasi objekFebriyani Syafri
 
Real time database
Real time databaseReal time database
Real time databasearvinthsaran
 
Bab 3 resolusi logika ta 2019
Bab 3 resolusi logika ta 2019Bab 3 resolusi logika ta 2019
Bab 3 resolusi logika ta 2019
Sukma Puspitorini
 
Interpolation with Finite differences
Interpolation with Finite differencesInterpolation with Finite differences
Interpolation with Finite differences
Dr. Nirav Vyas
 
K-Means Clustering.ppt
K-Means Clustering.pptK-Means Clustering.ppt
K-Means Clustering.ppt
Adam Superman
 
Pertemuan 2-pemecahan-masalah-ai
Pertemuan 2-pemecahan-masalah-aiPertemuan 2-pemecahan-masalah-ai
Pertemuan 2-pemecahan-masalah-aiwillyhayon
 
Pertemuan 4-metode-pencarian-dan-pelacakan
Pertemuan 4-metode-pencarian-dan-pelacakanPertemuan 4-metode-pencarian-dan-pelacakan
Pertemuan 4-metode-pencarian-dan-pelacakanwillyhayon
 
Lecture 4 principles of parallel algorithm design updated
Lecture 4   principles of parallel algorithm design updatedLecture 4   principles of parallel algorithm design updated
Lecture 4 principles of parallel algorithm design updated
Vajira Thambawita
 
Pertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptx
Pertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptxPertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptx
Pertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptx
Yaya610291
 
EMNLP 2014: Opinion Mining with Deep Recurrent Neural Network
EMNLP 2014: Opinion Mining with Deep Recurrent Neural NetworkEMNLP 2014: Opinion Mining with Deep Recurrent Neural Network
EMNLP 2014: Opinion Mining with Deep Recurrent Neural Network
Peinan ZHANG
 
05c neural network-mlp
05c neural network-mlp05c neural network-mlp
05c neural network-mlp
rrahmad_14
 
Cochran-Mantel-Haenszel Test with Breslow-Day & Tarone Correction
Cochran-Mantel-Haenszel Test with Breslow-Day & Tarone CorrectionCochran-Mantel-Haenszel Test with Breslow-Day & Tarone Correction
Cochran-Mantel-Haenszel Test with Breslow-Day & Tarone Correction
Azmi Mohd Tamil
 
Algoritma dan Struktur Data - Abstract Data Type
Algoritma dan Struktur Data - Abstract Data TypeAlgoritma dan Struktur Data - Abstract Data Type
Algoritma dan Struktur Data - Abstract Data Type
KuliahKita
 
Aps02 methodology
Aps02 methodologyAps02 methodology
Aps02 methodology
Arif Rahman
 
Graph dalam Struktur Data
Graph dalam Struktur DataGraph dalam Struktur Data
Graph dalam Struktur Data
Made Aditya
 
Sequential Probability Ratio Test for Sparse Signals
Sequential Probability Ratio Test for Sparse SignalsSequential Probability Ratio Test for Sparse Signals
Sequential Probability Ratio Test for Sparse Signals
Mohamed Seif
 
Anava 2 arah
Anava 2 arahAnava 2 arah
Anava 2 arahyositria
 
4. ukuran gejala pusat
4. ukuran gejala pusat4. ukuran gejala pusat
4. ukuran gejala pusatFarhatunisa
 

What's hot (20)

Stat matematika II (2)
Stat matematika II (2)Stat matematika II (2)
Stat matematika II (2)
 
Rpl 012 - perancangan berorientasi objek
Rpl   012 - perancangan berorientasi objekRpl   012 - perancangan berorientasi objek
Rpl 012 - perancangan berorientasi objek
 
Real time database
Real time databaseReal time database
Real time database
 
Bab 3 resolusi logika ta 2019
Bab 3 resolusi logika ta 2019Bab 3 resolusi logika ta 2019
Bab 3 resolusi logika ta 2019
 
Interpolation with Finite differences
Interpolation with Finite differencesInterpolation with Finite differences
Interpolation with Finite differences
 
K-Means Clustering.ppt
K-Means Clustering.pptK-Means Clustering.ppt
K-Means Clustering.ppt
 
Pertemuan 2-pemecahan-masalah-ai
Pertemuan 2-pemecahan-masalah-aiPertemuan 2-pemecahan-masalah-ai
Pertemuan 2-pemecahan-masalah-ai
 
Pertemuan 4-metode-pencarian-dan-pelacakan
Pertemuan 4-metode-pencarian-dan-pelacakanPertemuan 4-metode-pencarian-dan-pelacakan
Pertemuan 4-metode-pencarian-dan-pelacakan
 
Lecture 4 principles of parallel algorithm design updated
Lecture 4   principles of parallel algorithm design updatedLecture 4   principles of parallel algorithm design updated
Lecture 4 principles of parallel algorithm design updated
 
Pertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptx
Pertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptxPertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptx
Pertemuan Ke-11 - Sistem Operasi -Sistem Berkas.pptx
 
EMNLP 2014: Opinion Mining with Deep Recurrent Neural Network
EMNLP 2014: Opinion Mining with Deep Recurrent Neural NetworkEMNLP 2014: Opinion Mining with Deep Recurrent Neural Network
EMNLP 2014: Opinion Mining with Deep Recurrent Neural Network
 
05c neural network-mlp
05c neural network-mlp05c neural network-mlp
05c neural network-mlp
 
Cochran-Mantel-Haenszel Test with Breslow-Day & Tarone Correction
Cochran-Mantel-Haenszel Test with Breslow-Day & Tarone CorrectionCochran-Mantel-Haenszel Test with Breslow-Day & Tarone Correction
Cochran-Mantel-Haenszel Test with Breslow-Day & Tarone Correction
 
Algoritma dan Struktur Data - Abstract Data Type
Algoritma dan Struktur Data - Abstract Data TypeAlgoritma dan Struktur Data - Abstract Data Type
Algoritma dan Struktur Data - Abstract Data Type
 
Analisis Regresi
Analisis RegresiAnalisis Regresi
Analisis Regresi
 
Aps02 methodology
Aps02 methodologyAps02 methodology
Aps02 methodology
 
Graph dalam Struktur Data
Graph dalam Struktur DataGraph dalam Struktur Data
Graph dalam Struktur Data
 
Sequential Probability Ratio Test for Sparse Signals
Sequential Probability Ratio Test for Sparse SignalsSequential Probability Ratio Test for Sparse Signals
Sequential Probability Ratio Test for Sparse Signals
 
Anava 2 arah
Anava 2 arahAnava 2 arah
Anava 2 arah
 
4. ukuran gejala pusat
4. ukuran gejala pusat4. ukuran gejala pusat
4. ukuran gejala pusat
 

Viewers also liked

Whizle For Learners
Whizle For LearnersWhizle For Learners
Whizle For Learners
humanist3
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
Mohammed Hussein
 
Multimedia lecture ActionScript3
Multimedia lecture ActionScript3Multimedia lecture ActionScript3
Multimedia lecture ActionScript3
Mohammed Hussein
 
Wireless lecture1
Wireless lecture1Wireless lecture1
Wireless lecture1
Mohammed Hussein
 
02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrencesNoushadur Shoukhin
 
02 greedy, d&c, binary search
02 greedy, d&c, binary search02 greedy, d&c, binary search
02 greedy, d&c, binary searchPankaj Prateek
 
02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer
Andres Mendez-Vazquez
 
Iteration, induction, and recursion
Iteration, induction, and recursionIteration, induction, and recursion
Iteration, induction, and recursion
Mohammed Hussein
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
Muhammad Sarfraz
 
Internet programming lecture 1
Internet programming lecture 1Internet programming lecture 1
Internet programming lecture 1Mohammed Hussein
 
Algorithm Analyzing
Algorithm AnalyzingAlgorithm Analyzing
Algorithm Analyzing
Haluan Irsad
 
Multimedia Network
Multimedia NetworkMultimedia Network
Multimedia Network
Mohammed Hussein
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
Mohammed Hussein
 
Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)
Adam Mukharil Bachtiar
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
Amrinder Arora
 

Viewers also liked (20)

Whizle For Learners
Whizle For LearnersWhizle For Learners
Whizle For Learners
 
JAVA SCRIPT
JAVA SCRIPTJAVA SCRIPT
JAVA SCRIPT
 
Multimedia lecture ActionScript3
Multimedia lecture ActionScript3Multimedia lecture ActionScript3
Multimedia lecture ActionScript3
 
Multimedia lecture6
Multimedia lecture6Multimedia lecture6
Multimedia lecture6
 
Wireless lecture1
Wireless lecture1Wireless lecture1
Wireless lecture1
 
02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences02 asymptotic-notation-and-recurrences
02 asymptotic-notation-and-recurrences
 
02 greedy, d&c, binary search
02 greedy, d&c, binary search02 greedy, d&c, binary search
02 greedy, d&c, binary search
 
02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer02 Analysis of Algorithms: Divide and Conquer
02 Analysis of Algorithms: Divide and Conquer
 
Iteration, induction, and recursion
Iteration, induction, and recursionIteration, induction, and recursion
Iteration, induction, and recursion
 
Divide and conquer
Divide and conquerDivide and conquer
Divide and conquer
 
Comnet Network Simulation
Comnet Network SimulationComnet Network Simulation
Comnet Network Simulation
 
PHP
 PHP PHP
PHP
 
Internet programming lecture 1
Internet programming lecture 1Internet programming lecture 1
Internet programming lecture 1
 
Algorithm Analyzing
Algorithm AnalyzingAlgorithm Analyzing
Algorithm Analyzing
 
Multimedia Network
Multimedia NetworkMultimedia Network
Multimedia Network
 
Control system
Control systemControl system
Control system
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)Data Management (Data Mining Klasifikasi)
Data Management (Data Mining Klasifikasi)
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Divide and Conquer - Part 1
Divide and Conquer - Part 1Divide and Conquer - Part 1
Divide and Conquer - Part 1
 

Similar to Lec3 Algott

mit 演算法 Lec2
mit 演算法 Lec2 mit 演算法 Lec2
mit 演算法 Lec2 Henry Chang
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File UploadJoe Suh
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File UploadJoe Suh
 
AmortizedAnalysis
AmortizedAnalysisAmortizedAnalysis
AmortizedAnalysis
i222960MuhammadAhmer
 
Euler's work on Fermat's Last Theorem
Euler's work on Fermat's Last TheoremEuler's work on Fermat's Last Theorem
Euler's work on Fermat's Last TheoremLee Stemkoski
 
Lec2 Algorth
Lec2 AlgorthLec2 Algorth
Lec2 Algorthhumanist3
 
Jurnal informatika
Jurnal informatika Jurnal informatika
Jurnal informatika
MamaMa28
 
Lesson 9: The Derivative as a function
Lesson 9: The Derivative as a functionLesson 9: The Derivative as a function
Lesson 9: The Derivative as a functionMatthew Leingang
 
Lesson 5: Continuity
Lesson 5: ContinuityLesson 5: Continuity
Lesson 5: Continuity
Matthew Leingang
 

Similar to Lec3 Algott (9)

mit 演算法 Lec2
mit 演算法 Lec2 mit 演算法 Lec2
mit 演算法 Lec2
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File Upload
 
Mychurch File Upload
Mychurch File UploadMychurch File Upload
Mychurch File Upload
 
AmortizedAnalysis
AmortizedAnalysisAmortizedAnalysis
AmortizedAnalysis
 
Euler's work on Fermat's Last Theorem
Euler's work on Fermat's Last TheoremEuler's work on Fermat's Last Theorem
Euler's work on Fermat's Last Theorem
 
Lec2 Algorth
Lec2 AlgorthLec2 Algorth
Lec2 Algorth
 
Jurnal informatika
Jurnal informatika Jurnal informatika
Jurnal informatika
 
Lesson 9: The Derivative as a function
Lesson 9: The Derivative as a functionLesson 9: The Derivative as a function
Lesson 9: The Derivative as a function
 
Lesson 5: Continuity
Lesson 5: ContinuityLesson 5: Continuity
Lesson 5: Continuity
 

More from humanist3

Whizle Edu Scenario
Whizle Edu ScenarioWhizle Edu Scenario
Whizle Edu Scenario
humanist3
 
Whizle U
Whizle UWhizle U
Whizle U
humanist3
 
Lec1 Algorthm
Lec1 AlgorthmLec1 Algorthm
Lec1 Algorthmhumanist3
 
Lecture1webhand
Lecture1webhandLecture1webhand
Lecture1webhandhumanist3
 
Whizle Demo
Whizle DemoWhizle Demo
Whizle Demo
humanist3
 
Lecture2
Lecture2Lecture2
Lecture2
humanist3
 
Control of Manufacturing Processes
Control of Manufacturing ProcessesControl of Manufacturing Processes
Control of Manufacturing Processes
humanist3
 

More from humanist3 (7)

Whizle Edu Scenario
Whizle Edu ScenarioWhizle Edu Scenario
Whizle Edu Scenario
 
Whizle U
Whizle UWhizle U
Whizle U
 
Lec1 Algorthm
Lec1 AlgorthmLec1 Algorthm
Lec1 Algorthm
 
Lecture1webhand
Lecture1webhandLecture1webhand
Lecture1webhand
 
Whizle Demo
Whizle DemoWhizle Demo
Whizle Demo
 
Lecture2
Lecture2Lecture2
Lecture2
 
Control of Manufacturing Processes
Control of Manufacturing ProcessesControl of Manufacturing Processes
Control of Manufacturing Processes
 

Recently uploaded

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 

Recently uploaded (20)

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 

Lec3 Algott

  • 1. Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and Conquer • Binary search • Powering a number • Fibonacci numbers • Matrix multiplication • Strassen’s algorithm • VLSI tree layout Prof. Erik D. Demaine September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.1
  • 2. The divide-and-conquer design paradigm 1. Divide the problem (instance) into subproblems. 2. Conquer the subproblems by solving them recursively. 3. Combine subproblem solutions. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.2
  • 3. Merge sort 1. Divide: Trivial. 2. Conquer: Recursively sort 2 subarrays. 3. Combine: Linear-time merge. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.3
  • 4. Merge sort 1. Divide: Trivial. 2. Conquer: Recursively sort 2 subarrays. 3. Combine: Linear-time merge. T(n) = 2 T(n/2) + Θ(n) # subproblems work dividing and combining subproblem size September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.4
  • 5. Master theorem (reprise) T(n) = a T(n/b) + f (n) CASE 1: f (n) = O(nlogba – ε), constant ε > 0 ⇒ T(n) = Θ(nlogba) . CASE 2: f (n) = Θ(nlogba lgkn), constant k ≥ 0 ⇒ T(n) = Θ(nlogba lgk+1n) . CASE 3: f (n) = Ω(nlogba + ε ), constant ε > 0, and regularity condition ⇒ T(n) = Θ( f (n)) . September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.5
  • 6. Master theorem (reprise) T(n) = a T(n/b) + f (n) CASE 1: f (n) = O(nlogba – ε), constant ε > 0 ⇒ T(n) = Θ(nlogba) . CASE 2: f (n) = Θ(nlogba lgkn), constant k ≥ 0 ⇒ T(n) = Θ(nlogba lgk+1n) . CASE 3: f (n) = Ω(nlogba + ε ), constant ε > 0, and regularity condition ⇒ T(n) = Θ( f (n)) . Merge sort: a = 2, b = 2 ⇒ nlogba = nlog22 = n ⇒ CASE 2 (k = 0) ⇒ T(n) = Θ(n lg n) . September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.6
  • 7. Binary search Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.7
  • 8. Binary search Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial. Example: Find 9 3 5 7 8 9 12 15 September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.8
  • 9. Binary search Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial. Example: Find 9 3 5 7 8 9 12 15 September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.9
  • 10. Binary search Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial. Example: Find 9 3 5 7 8 9 12 15 September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.10
  • 11. Binary search Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial. Example: Find 9 3 5 7 8 9 12 15 September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.11
  • 12. Binary search Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial. Example: Find 9 3 5 7 8 9 12 15 September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.12
  • 13. Binary search Find an element in a sorted array: 1. Divide: Check middle element. 2. Conquer: Recursively search 1 subarray. 3. Combine: Trivial. Example: Find 9 3 5 7 8 9 12 15 September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.13
  • 14. Recurrence for binary search T(n) = 1 T(n/2) + Θ(1) # subproblems work dividing and combining subproblem size September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.14
  • 15. Recurrence for binary search T(n) = 1 T(n/2) + Θ(1) # subproblems work dividing and combining subproblem size nlogba = nlog21 = n0 = 1 ⇒ CASE 2 (k = 0) ⇒ T(n) = Θ(lg n) . September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.15
  • 16. Powering a number Problem: Compute a n, where n ∈ N. Naive algorithm: Θ(n). September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.16
  • 17. Powering a number Problem: Compute a n, where n ∈ N. Naive algorithm: Θ(n). Divide-and-conquer algorithm: a n/2 ⋅ a n/2 if n is even; an = a (n–1)/2 ⋅ a (n–1)/2 ⋅ a if n is odd. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.17
  • 18. Powering a number Problem: Compute a n, where n ∈ N. Naive algorithm: Θ(n). Divide-and-conquer algorithm: a n/2 ⋅ a n/2 if n is even; an = a (n–1)/2 ⋅ a (n–1)/2 ⋅ a if n is odd. T(n) = T(n/2) + Θ(1) ⇒ T(n) = Θ(lg n) . September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.18
  • 19. Fibonacci numbers Recursive definition: 0 if n = 0; Fn = 1 if n = 1; Fn–1 + Fn–2 if n ≥ 2. 0 1 1 2 3 5 8 13 21 34 L September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.19
  • 20. Fibonacci numbers Recursive definition: 0 if n = 0; Fn = 1 if n = 1; Fn–1 + Fn–2 if n ≥ 2. 0 1 1 2 3 5 8 13 21 34 L Naive recursive algorithm: Ω(φ n) (exponential time), where φ = (1 + 5) / 2 is the golden ratio. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.20
  • 21. Computing Fibonacci numbers Bottom-up: • Compute F0, F1, F2, …, Fn in order, forming each number by summing the two previous. • Running time: Θ(n). September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.21
  • 22. Computing Fibonacci numbers Bottom-up: • Compute F0, F1, F2, …, Fn in order, forming each number by summing the two previous. • Running time: Θ(n). Naive recursive squaring: Fn = φ n/ 5 rounded to the nearest integer. • Recursive squaring: Θ(lg n) time. • This method is unreliable, since floating-point arithmetic is prone to round-off errors. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.22
  • 23. Recursive squaring n ⎡ Fn +1 Fn ⎤ ⎡1 1⎤ Theorem: ⎢ ⎥ = ⎢1 0⎥ . ⎣ Fn Fn −1 ⎦ ⎣ ⎦ September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.23
  • 24. Recursive squaring n ⎡ Fn +1 Fn ⎤ ⎡1 1⎤ Theorem: ⎢ ⎥ = ⎢1 0⎥ . ⎣ Fn Fn −1 ⎦ ⎣ ⎦ Algorithm: Recursive squaring. Time = Θ(lg n) . September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.24
  • 25. Recursive squaring n ⎡ Fn +1 Fn ⎤ ⎡1 1⎤ Theorem: ⎢ ⎥ = ⎢1 0⎥ . ⎣ Fn Fn −1 ⎦ ⎣ ⎦ Algorithm: Recursive squaring. Time = Θ(lg n) . Proof of theorem. (Induction on n.) ⎡ F2 F1 ⎤ ⎡1 1⎤ 1 Base (n = 1): ⎢ =⎢ . ⎣ F1 F0 ⎥ ⎣1 0⎥ ⎦ ⎦ September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.25
  • 26. Recursive squaring Inductive step (n ≥ 2): . ⎡ Fn +1 Fn ⎤ ⎡ Fn Fn −1 ⎤ ⎡1 1⎤ ⎢ F ⎥ = ⎢F ⎥ ⋅ ⎢1 0⎥ Fn −1 ⎦ ⎣ n −1 Fn − 2 ⎦ ⎣ ⎣ n ⎦ n−1 ⎡1 1⎤ ⎡1 1⎤ =⎢ ⎥ ⋅⎢ ⎥. ⎣1 0⎦ ⎣1 0⎦ n ⎡1 1⎤ =⎢ ⎣1 0⎥ ⎦ September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.26
  • 27. Matrix multiplication Input: A = [aij], B = [bij]. i, j = 1, 2,… , n. Output: C = [cij] = A⋅ B. ⎡ c11 c12 L c1n ⎤ ⎡ a11 a12 L a1n ⎤ ⎡ b11 b12 L b1n ⎤ ⎢c c L c2 n ⎥ ⎢a21 a22 L a2 n ⎥ ⎢b21 b22 L b2 n ⎥ ⎢ 21 22 ⎥=⎢ ⎥⋅⎢ ⎥ ⎢ M M O M ⎥ ⎢ M M O M ⎥ ⎢ M M O M ⎥ ⎢c c L cnn ⎥ ⎣ an1 an 2 ⎢ L ann ⎥ ⎢bn1 bn 2 L bnn ⎥ ⎣ n1 n 2 ⎦ ⎦ ⎣ ⎦ n cij = ∑ aik ⋅ bkj k =1 September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.27
  • 28. Standard algorithm for i ← 1 to n do for j ← 1 to n do cij ← 0 for k ← 1 to n do cij ← cij + aik⋅ bkj September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.28
  • 29. Standard algorithm for i ← 1 to n do for j ← 1 to n do cij ← 0 for k ← 1 to n do cij ← cij + aik⋅ bkj Running time = Θ(n3) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.29
  • 30. Divide-and-conquer algorithm IDEA: n×n matrix = 2×2 matrix of (n/2)×(n/2) submatrices: ⎡r s ⎤ ⎡a b ⎤ ⎡ e f ⎤ ⎢ t u ⎥ = ⎢c d ⎥ ⋅ ⎢ g h ⎥ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ C = A ⋅ B r = ae + bg s = af + bh 8 mults of (n/2)×(n/2) submatrices t = ce + dg 4 adds of (n/2)×(n/2) submatrices u = cf + dh September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.30
  • 31. Divide-and-conquer algorithm IDEA: n×n matrix = 2×2 matrix of (n/2)×(n/2) submatrices: ⎡r s ⎤ ⎡a b ⎤ ⎡ e f ⎤ ⎢ t u ⎥ = ⎢c d ⎥ ⋅ ⎢ g h ⎥ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ C = A ⋅ B r = ae + bg recursive s = af + bh 8 mults of (n/2)×(n/2) submatrices ^ t = ce + dh 4 adds of (n/2)×(n/2) submatrices u = cf + dg September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.31
  • 32. Analysis of D&C algorithm T(n) = 8 T(n/2) + Θ(n2) # submatrices work adding submatrices submatrix size September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.32
  • 33. Analysis of D&C algorithm T(n) = 8 T(n/2) + Θ(n2) # submatrices work adding submatrices submatrix size nlogba = nlog28 = n3 ⇒ CASE 1 ⇒ T(n) = Θ(n3). September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.33
  • 34. Analysis of D&C algorithm T(n) = 8 T(n/2) + Θ(n2) # submatrices work adding submatrices submatrix size nlogba = nlog28 = n3 ⇒ CASE 1 ⇒ T(n) = Θ(n3). No better than the ordinary algorithm. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.34
  • 35. Strassen’s idea • Multiply 2×2 matrices with only 7 recursive mults. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.35
  • 36. Strassen’s idea • Multiply 2×2 matrices with only 7 recursive mults. P1 = a ⋅ ( f – h) P2 = (a + b) ⋅ h P3 = (c + d) ⋅ e P4 = d ⋅ (g – e) P5 = (a + d) ⋅ (e + h) P6 = (b – d) ⋅ (g + h) P7 = (a – c) ⋅ (e + f ) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.36
  • 37. Strassen’s idea • Multiply 2×2 matrices with only 7 recursive mults. P1 = a ⋅ ( f – h) r = P5 + P4 – P2 + P6 P2 = (a + b) ⋅ h s = P1 + P2 P3 = (c + d) ⋅ e t = P3 + P4 P4 = d ⋅ (g – e) u = P5 + P1 – P3 – P7 P5 = (a + d) ⋅ (e + h) P6 = (b – d) ⋅ (g + h) P7 = (a – c) ⋅ (e + f ) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.37
  • 38. Strassen’s idea • Multiply 2×2 matrices with only 7 recursive mults. P1 = a ⋅ ( f – h) r = P5 + P4 – P2 + P6 P2 = (a + b) ⋅ h s = P1 + P2 P3 = (c + d) ⋅ e t = P3 + P4 P4 = d ⋅ (g – e) u = P5 + P1 – P3 – P7 P5 = (a + d) ⋅ (e + h) P6 = (b – d) ⋅ (g + h) 7 mults, 18 adds/subs. 7 mults, 18 adds/subs. P7 = (a – c) ⋅ (e + f ) Note: No reliance on Note: No reliance on commutativity of mult! commutativity of mult! September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.38
  • 39. Strassen’s idea • Multiply 2×2 matrices with only 7 recursive mults. P1 = a ⋅ ( f – h) r = P5 + P4 – P2 + P6 P2 = (a + b) ⋅ h = (a + d) (e + h) P3 = (c + d) ⋅ e + d (g – e) – (a + b) h P4 = d ⋅ (g – e) + (b – d) (g + h) P5 = (a + d) ⋅ (e + h) = ae + ah + de + dh P6 = (b – d) ⋅ (g + h) + dg –de – ah – bh P7 = (a – c) ⋅ (e + f ) + bg + bh – dg – dh = ae + bg September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.39
  • 40. Strassen’s algorithm 1. Divide: Partition A and B into (n/2)×(n/2) submatrices. Form terms to be multiplied using + and – . 2. Conquer: Perform 7 multiplications of (n/2)×(n/2) submatrices recursively. 3. Combine: Form C using + and – on (n/2)×(n/2) submatrices. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.40
  • 41. Strassen’s algorithm 1. Divide: Partition A and B into (n/2)×(n/2) submatrices. Form terms to be multiplied using + and – . 2. Conquer: Perform 7 multiplications of (n/2)×(n/2) submatrices recursively. 3. Combine: Form C using + and – on (n/2)×(n/2) submatrices. T(n) = 7 T(n/2) + Θ(n2) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.41
  • 42. Analysis of Strassen T(n) = 7 T(n/2) + Θ(n2) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.42
  • 43. Analysis of Strassen T(n) = 7 T(n/2) + Θ(n2) nlogba = nlog27 ≈ n2.81 ⇒ CASE 1 ⇒ T(n) = Θ(nlg 7). September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.43
  • 44. Analysis of Strassen T(n) = 7 T(n/2) + Θ(n2) nlogba = nlog27 ≈ n2.81 ⇒ CASE 1 ⇒ T(n) = Θ(nlg 7). The number 2.81 may not seem much smaller than 3, but because the difference is in the exponent, the impact on running time is significant. In fact, Strassen’s algorithm beats the ordinary algorithm on today’s machines for n ≥ 32 or so. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.44
  • 45. Analysis of Strassen T(n) = 7 T(n/2) + Θ(n2) nlogba = nlog27 ≈ n2.81 ⇒ CASE 1 ⇒ T(n) = Θ(nlg 7). The number 2.81 may not seem much smaller than 3, but because the difference is in the exponent, the impact on running time is significant. In fact, Strassen’s algorithm beats the ordinary algorithm on today’s machines for n ≥ 32 or so. Best to date (of theoretical interest only): Θ(n2.376L). September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.45
  • 46. VLSI layout Problem: Embed a complete binary tree with n leaves in a grid using minimal area. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.46
  • 47. VLSI layout Problem: Embed a complete binary tree with n leaves in a grid using minimal area. W(n) H(n) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.47
  • 48. VLSI layout Problem: Embed a complete binary tree with n leaves in a grid using minimal area. W(n) H(n) H(n) = H(n/2) + Θ(1) = Θ(lg n) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.48
  • 49. VLSI layout Problem: Embed a complete binary tree with n leaves in a grid using minimal area. W(n) H(n) H(n) = H(n/2) + Θ(1) W(n) = 2 W(n/2) + Θ(1) = Θ(lg n) = Θ(n) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.49
  • 50. VLSI layout Problem: Embed a complete binary tree with n leaves in a grid using minimal area. W(n) H(n) H(n) = H(n/2) + Θ(1) W(n) = 2 W(n/2) + Θ(1) = Θ(lg n) = Θ(n) Area = Θ(n lg n) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.50
  • 51. H-tree embedding L(n) L(n) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.51
  • 52. H-tree embedding L(n) L(n) L(n/4) Θ(1) L(n/4) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.52
  • 53. H-tree embedding L(n) L(n) = 2 L(n/4) + Θ(1) = Θ( n ) L(n) Area = Θ(n) L(n/4) Θ(1) L(n/4) September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.53
  • 54. Conclusion • Divide and conquer is just one of several powerful techniques for algorithm design. • Divide-and-conquer algorithms can be analyzed using recurrences and the master method (so practice this math). • The divide-and-conquer strategy often leads to efficient algorithms. September 14, 2005 Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson L2.54