def f0(n): count = 0 for x in xrange(n): for y in xrange(1, n): count += 1 return count def f1(n): count = 0 for x in xrange(n): for y in xrange(1, x): # note ranges to x, not n count += 1 return count def f2(n): count = 0 for x in xrange(1,n/2, 2): for y in xrange(1, x/2): count += 1 return count def f3(n): count = 0 for x in xrange(1,n): for y in xrange(1, n, n/100): count += 1 return count def f4(n): count = n**2 # note: not setting count = 0 while (n > 0): count += 1 n /= 2 return count def f5(n): count = 0 for x in xrange(1, n): count += f4(n) return count def f6(n): return f1(f2(n))
n = 250 print 1.0*f0(2*n)/f0(n) print 1.0*f6(2*n)/f6(n)
Try all the different functions from the previous
problem, and not just f0 and f6. You may need to adjust the values of n to
get meaningful results. The O(n2) functions should converge on
4, the others on values larger or smaller depending on their function families.
Do these results match the big-oh families from your previous answers?
carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem - carpe diem