Example #1
0
        done = False
        while not done:

            while leftMark <= rightMark and input[leftMark] <= pivotvalue:
                leftMark = leftMark + 1

            while input[rightMark] >= pivotvalue and rightMark >= leftMark:
                rightMark = rightMark - 1

            if rightMark < leftMark:
                done = True
            else:
                temp = input[leftMark]
                input[leftMark] = input[rightMark]
                input[rightMark] = temp

        temp = input[first]
        input[first] = input[rightMark]
        input[rightMark] = temp

        return rightMark


if __name__ == '__main__':
    sys.setrecursionlimit(5000)
    print "sorting input of size 1000"
    input = CreateDataUtility().CreateWorstCaseData(10000)
    print input
    QuickSort().sort(input)
    print input
#Helps find the run time sort method of a instatiation of a sorting implementatiom
def recordTime(sortObject, input):
    start_time = timeit.default_timer()
    sortObject.sort(input)
    elapsed = timeit.default_timer() - start_time
    return elapsed * 100


#Input Sizes
inputSizes = [
    1000, 2000, 5000, 10000, 20000, 25000, 40000, 50000, 60000, 75000, 100000
]

#Creating objects of sorting implementation and data Creation utility
data = CreateDataUtility()
insertionSort = InsertionSort()
mergeSort = MergeSort()
quickSort = QuickSort()
modifiedQuickSort = ModifiedQuickSort()

#Creating a csv file with results in "Results/" folder
with open('Results/Running-times-average-case.csv', mode='w') as csv_file:
    writer = csv.writer(csv_file, delimiter=',')
    writer.writerow(['Sort Algorithm', 'input Size', 'Time Taken'])
    for inputSize in inputSizes:
        input = data.CreateAverageCaseData(inputSize)
        sys.setrecursionlimit(max(sys.getrecursionlimit(), len(input) + 50000))
        insertionSortInput = []
        insertionSortInput.extend(input)
        mergeSortInput = []
Example #3
0
        pivotindex = self.median(input, first, last, (first + last) / 2)
        input[first], input[pivotindex] = input[pivotindex], input[first]
        pivotvalue = input[first]

        leftMark = first + 1
        rightMark = last

        done = False
        while not done:

            while leftMark <= rightMark and input[leftMark] <= pivotvalue:
                leftMark = leftMark + 1

            while input[rightMark] >= pivotvalue and rightMark >= leftMark:
                rightMark = rightMark - 1

            if rightMark < leftMark:
                done = True
            else:
                self.swap(input, leftMark, rightMark)

        self.swap(input, leftMark, rightMark)
        return rightMark


if __name__ == '__main__':
    input = CreateDataUtility().CreateAverageData(1000)
    print "sorting input of size 1000"
    print input
    output = ModifiedQuickSort().sort(input)
    print output
Example #4
0
import timeit
import csv
import sys

#Helps find the run time sort method of a instatiation of a sorting implementatiom
def recordTime(sortObject,input):
    start_time = timeit.default_timer()
    sortObject.sort(input)
    elapsed = timeit.default_timer() - start_time
    return elapsed*100

#Input Sizes
inputSizes = [100,500,1000,2000,5000,10000,15000,20000]

#Creating objects of sorting implementation and data Creation utility
data = CreateDataUtility()
insertionSort = InsertionSort()
mergeSort = MergeSort()
quickSort = QuickSort()
modifiedQuickSort = ModifiedQuickSort()

#Creating a csv file with results in "Results/" folder
with open('Results/Running-times-Worst-case.csv',mode='w') as csv_file:
    writer = csv.writer(csv_file, delimiter=',')
    writer.writerow(['Sort Algorithm', 'input Size', 'Time Taken'])
    for inputSize in inputSizes:
        input = data.CreateWorstCaseData(inputSize)
        sys.setrecursionlimit(max(sys.getrecursionlimit(), len(input) + 50000))
        insertionSortInput = []
        insertionSortInput.extend(input)
        mergeSortInput = []