Programming Problem solving by using python language
Programming Problem solving by using python language
Create a function that will generate a list of random numbers. Be sure the numbers are in random order. The function should accept a number that represents the size of the list and return the list. Modify the Insertion sort, Select sort and Merge sort functions to perform benchmark analysis on each of these functions. You can use some type of counting such as comparisons and /or swaps or you could use time. These files are mentioned:
Insertion sort:
def insertionSort(alist):
for index in range(1, len(alist)):
currentValue = alist[index]
position = index
while position > 0 and alist[position – 1] > currentValue:
alist[position] = alist[position – 1]
position -= 1
alist[position] = currentValue
Selection sort:
def selectionSort(alist):
for fillslot in range(len(alist) – 1, 0, -1):
positionOfMax = 0
for location in range(1, fillslot + 1):
if alist[location] > alist[positionOfMax]:
positionOfMax = location
temp = alist[fillslot]
alist[fillslot] = alist[positionOfMax]
alist[positionOfMax] = temp
Merge sort:
def mergeSort(alist):
if len(alist) > 1:
mid = len(alist) // 2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
i = 0
j = 0
k = 0
while i < len(lefthalf) and j < len(righthalf):
if lefthalf[i] < righthalf[j]:
alist[k] = lefthalf[i]
i = i + 1
else:
alist[k] = righthalf[j]
j = j + 1
k = k + 1
while i < len(lefthalf):
alist[k] = lefthalf[i]
i = i + 1
k = k + 1
while j < len(righthalf):
alist[k] = righthalf[j]
j = j + 1
k = k + 1
Note: Run the benchmark analysis on each sorting function for list sizes of 100, 1000, and 10000. Print the size and the benchmark values (time or counts). Please use Python language
Part2: Use the binaryList. You will need to read the numbers into a list. Run a for loop 20 times searching for the 20 numbers locationed in the binaryLook.txt file. Analyze these searched using comparison.
part-3: Use the hashList.txt file (mentioned in the below). Using the hash search (mid-square method), move the numbers from the file to a hash list. Suggested size for the hash list is 1171. Once the list is created, use the hash function to search for 20 numbers founds in the hashLook.txt file. Analyze these searches using comparison. Write an essay completely explaining the two search methods.
"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.
Discount Code: CIPD30
Click ORDER NOW..


