Ejemplo n.º 1
0
def test_week1_exercise_Q1(): # Lecture: Quick-Union Improvements 1:22
  """seed = 254585 """
  # estimate b: 7:58
  #        N   seconds
  # -------------------
  strData = """
        16384     0.000
        32768     0.001
        65536     0.001
       131072     0.004
       262144     0.009
       524288     0.023
      1048576     0.059
      2097152     0.152
      4194304     0.389
      8388608     0.996
     16777216     2.553
     33554432     6.540
     67108864    16.756
    134217728    42.927
    268435456   109.962
    536870912   281.688
  """
  data = getData(strData)
  b = est_b(data)
  a = solve_a(data, b)
  do_plot(data, a, b)
Ejemplo n.º 2
0
def test_week1_exercise_Q1():  # Lecture: Quick-Union Improvements 1:22
    """seed = 254585 """
    # estimate b: 7:58
    #        N   seconds
    # -------------------
    strData = """
        16384     0.000
        32768     0.001
        65536     0.001
       131072     0.004
       262144     0.009
       524288     0.023
      1048576     0.059
      2097152     0.152
      4194304     0.389
      8388608     0.996
     16777216     2.553
     33554432     6.540
     67108864    16.756
    134217728    42.927
    268435456   109.962
    536870912   281.688
  """
    data = getData(strData)
    b = est_b(data)
    a = solve_a(data, b)
    do_plot(data, a, b)
Ejemplo n.º 3
0
def test_Lecture_Observations_Question():
    """Question from the end of the Week 1 Lecture, Observations.

     EXPLANATION: We assume T(N) = aN^b for some constants a and b.
     As we double the size of the input N, the running time
     approximately quadruples, indicating a algorithm or b=2.
     Plugging in T(64,000) = 20.5 and solving for a, we obtain
     a = 20.5/64,000^2 ~ 5.0 x 10-9
  """
    strData = """
     1000  0.0
     2000  0.0
     4000  0.1
     8000  0.3
    16000  1.3
    32000  5.1
    64000 20.5
  """
    data = getData(strData)
    b = est_b(data)
    a = solve_a(data, b)
    do_plot(data, a, b)
Ejemplo n.º 4
0
def test_Lecture_Observations_Question():
  """Question from the end of the Week 1 Lecture, Observations.

     EXPLANATION: We assume T(N) = aN^b for some constants a and b.
     As we double the size of the input N, the running time
     approximately quadruples, indicating a algorithm or b=2.
     Plugging in T(64,000) = 20.5 and solving for a, we obtain
     a = 20.5/64,000^2 ~ 5.0 x 10-9
  """
  strData = """
     1000  0.0
     2000  0.0
     4000  0.1
     8000  0.3
    16000  1.3
    32000  5.1
    64000 20.5
  """
  data = getData(strData)
  b = est_b(data)
  a = solve_a(data, b)
  do_plot(data, a, b)