Example #1
0
def experimentalAnalysis(nMax, algoNo, stepSize):
	print "Generating array..."

	#generate array of test arrays
	testArray = []			

	for n in range(stepSize, nMax+1, stepSize):

		#need 10 test arrays of each input size n
		noTestArrays = 10
		for j in range(0, noTestArrays):
			testArray.append([])
			for k in range(0, n):
				testArray[-1].append(randint(-10, 10))

	#determine which algorithm we need to run
	if (algoNo == 1):
		print "Analysis for Algorithm 1"
		for a in testArray:					#test each array in the algorithm
			t0 = time()
			enum(a)							#call algorithm
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	elif (algoNo == 2):
		print "Analysis for Algorithm 2"
		for a in testArray:
			t0 = time()
			better(a)
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	elif (algoNo == 3):
		print "Analysis for Algorithm 3"
		for a in testArray:
			t0 = time()
			divideConquer(a, 0, len(a)-1)
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	elif(algoNo == 4):
		print "Analysis for Algorithm 4"
		for a in testArray:
			t0 = time()
			maxSubarrayLinear(a)
			t1 = time()
			print len(a), " %f" %(t1-t0) 

	else:
		print "Error: Invalid algorithm number."