Example #1
0
N = [100, 1000, 10000]
t_selection = np.zeros(len(N))
t_merge = np.zeros(len(N))

n = 10000
x = np.zeros(n)
N_squared = np.zeros(n)
N_log_N = np.zeros(n)

print("Ratios (selection/merge):")
for i in range(len(N)):
    A = np.random.rand(N[i])
    A2 = np.array(A)
    t0 = time.time()
    improc.selectionsort(A, N[i])
    t1 = time.time()
    improc.mergesort(A2, N[i])
    t2 = time.time()
    t_selection[i] = t1 - t0
    t_merge[i] = t2 - t1
    print(t_selection[i] / t_merge[i])
for i in range(1, n):
    x[i] = i
    N_squared[i] = 1.55e-7 * x[i] * x[i]
    N_log_N[i] = 1.5e-6 * x[i] * np.log2(x[i])

plt.plot(N, t_selection, 'ro', N, t_merge, 'bo', x, N_squared, 'r', x, N_log_N,
         'b')
plt.xlabel("N")
plt.ylabel("runtime (seconds)")
Example #2
0
import time
import Fibonacci
import matplotlib.pyplot as plt
n1 = 100
n2 = 1000
n3 = 10000

A1 = np.random.rand(n1)
A1_m = np.array(A1)
A2 = np.random.rand(n2)
A2_m = np.array(A2)
A3 = np.random.rand(n3)
A3_m = np.array(A3)
t0 = time.time()

improc.selectionsort(A1,n1)
t1_s = time.time()
improc.mergesort(A1_m,n1)
t1_m = time.time()
print(t1_s)
print(t1_m)
improc.selectionsort(A2,n2)
t2_s = time.time()
improc.mergesort(A2_m,n2)
t2_m = time.time()


improc.selectionsort(A3,n3)
t3_s = time.time()
improc.mergesort(A3_m,n3)
t3_m = time.time()
Example #3
0
#improc.show_n([img,smaller,diff])

n = 10000
n_vector=np.arange(0,n+1,1000)
n_vector2=np.array(n_vector)
n_vector2[0]=1
print(n_vector2)
length=len(n_vector2)
time_selectionsort = np.zeros(length)
time_mergesort = np.zeros(length)
for i in range(length):
 A = np.random.rand(n_vector2[i])
 A2 = np.array(A)
 print(i)
 t0 = time.time()
 improc.selectionsort(A,n_vector2[i])
 t1 = time.time()
 improc.mergesort(A2,int(n_vector2[i]))
 t2 = time.time()
 time_selectionsort[i]=t1-t0
 time_mergesort[i]=t2-t1
print(n_vector2)
print(time_selectionsort)
print(time_mergesort)

plt.plot(n_vector2,time_selectionsort,'r',n_vector2,time_mergesort,'b')
plt.xlabel("N")
plt.ylabel("time(s)")
plt.show()

#n=100
Example #4
0
N = [100,1000,10000]
t_selection = np.zeros(len(N))
t_merge = np.zeros(len(N))

n = 10000
x = np.zeros(n)
N_squared = np.zeros(n)
N_log_N = np.zeros(n)

print("Ratios (selection/merge):")
for i in range(len(N)):
  A = np.random.rand(N[i])
  A2 = np.array(A)
  t0 = time.time()
  improc.selectionsort(A,N[i])
  t1 = time.time()
  improc.mergesort(A2,N[i])
  t2 = time.time()
  t_selection[i] = t1 - t0
  t_merge[i] = t2 - t1
  print(t_selection[i]/t_merge[i])
for i in range(1,n):
  x[i] = i
  N_squared[i] = 1.55e-7*x[i]*x[i]
  N_log_N[i] = 1.5e-6*x[i]*np.log2(x[i])

plt.plot(N,t_selection,'ro',N,t_merge,'bo',x,N_squared,'r',x,N_log_N,'b')
plt.xlabel("N")
plt.ylabel("runtime (seconds)")
plt.legend(["selection sort", "merge sort", r"$N^2$", r"$N\log_2 N$"],
Example #5
0
#!/usr/bin/env python
import matplotlib.pyplot as plt
import numpy as np
import improc
import time
import fft

N = [100,1000,10000]
N1 = np.random.rand(100)
N2 = np.random.rand(1000)
N3 = np.random.rand(10000)

t0 = time.time()
N1_sel = improc.selectionsort(N1,100)
t1 = time.time()
N1_mer = improc.mergesort(N1,100)
t2 = time.time()
N2_sel = improc.selectionsort(N2,1000)
t3 = time.time()
N2_mer = improc.mergesort(N2,1000)
t4 = time.time()
N3_sel = improc.selectionsort(N3,10000)
t5 = time.time()
N3_mer = improc.mergesort(N3,10000)
t6 = time.time()

t_sel = [t1-t0,t3-t2,t5-t4]
t_mer = [t2-t1,t4-t3,t6-t5]
plt.figure()
plt.plot(N,t_sel,N,t_mer)
plt.legend(["selection sort","merge sort"])
import improc
import numpy as np
import time

img = improc.read("gilman-hall.jpg")

# removed red channel
#img_nored = improc.rm_red(img)

# convert to gray
#img_gray_avg = improc.rgb_to_gray_avg(img)
#img_gray_lum = improc.rgb_to_gray_lum(img)

#bigger = improc.scale(img,1.5)
#smaller = improc.scale(bigger,2/3)
#diff = improc.difference(smaller,img)

#improc.show_n([img,smaller,diff])

n = 500
A = np.random.rand(n)
A2 = np.array(A)
t0 = time.time()
improc.selectionsort(A,n)
t1 = time.time()
improc.mergesort(A2,n)
t2 = time.time()
print(t1-t0, t2-t1)

# I ADDED THIS LINE
import improc
import numpy as np
import time

img = improc.read("gilman-hall.jpg")

# removed red channel
#img_nored = improc.rm_red(img)

# convert to gray
#img_gray_avg = improc.rgb_to_gray_avg(img)
#img_gray_lum = improc.rgb_to_gray_lum(img)

#bigger = improc.scale(img,1.5)
#smaller = improc.scale(bigger,2/3)
#diff = improc.difference(smaller,img)

#improc.show_n([img,smaller,diff])

n = 500
A = np.random.rand(n)
A2 = np.array(A)
t0 = time.time()
improc.selectionsort(A, n)
t1 = time.time()
improc.mergesort(A2, n)
t2 = time.time()
print(t1 - t0, t2 - t1)

# I ADDED THIS LINE