Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Python by Kian ( 9 years ago )
from random import randint
import matplotlib.pyplot as plt
import time
InputList=[]
InputList2=[]
ll = []
ResultH,ResultQ,ResultBu,ResultBi,ResultL =[],[],[],[],[]
timeH,timeQ,timeBu,timeBi,timeL = 0,0,0,0,0

def TowerOfHanoi(n , from_rod, to_rod, aux_rod):
    if n == 1:
        print("1",from_rod,to_rod)
        return
    TowerOfHanoi(n-1, from_rod, aux_rod, to_rod)
    print(n,from_rod,to_rod)
    TowerOfHanoi(n-1, aux_rod, to_rod, from_rod)
def partition(arr, low, high):
    i = (low - 1)
    pivot = arr[high]
    for j in range(low, high):
        if arr[j] <= pivot:
            i = i + 1
            arr[i], arr[j] = arr[j], arr[i]
    arr[i + 1], arr[high] = arr[high], arr[i + 1]
    return (i + 1)
def quickSort(arr, low, high):
    if low < high xss=removed xss=removed> numbers[n+1]:
                numbers[n],numbers[n+1] = numbers[n+1],numbers[n]
        i += 1

def binary_search(item_list, item):
    first = 0
    last = len(item_list) - 1
    found = False
    while (first <= last and not found):
        mid = (first + last) // 2
        if item_list[mid] == item:
            found = True
        else:
            if item < item_list[mid]:
                last = mid - 1
            else:
                first = mid + 1
    print("foundBI")


def Linear_Search(lists,w):
    for x in range(len(lists)):
        if w == lists[x]:
            print("trueL")



for i in range(50):
    lenghtrand = randint(1,100)
    ll.append(lenghtrand)
    for i in range(lenghtrand):
        InputList.append(randint(1, 10000))
    InputList2 = InputList
    time1 = time.clock()
    quickSort(InputList, 0, len(InputList) - 1)
    time2 = time.clock()
    timeQ = time2 - time1
    ResultQ.append(timeQ*10**5)
    time1 = time.clock()
    Bubble_Sort(InputList2)
    time2 = time.clock()
    timeBu = time2 - time1
    ResultBu.append(timeBu*10**5)
    time1 = time.clock()
    binary_search(InputList, InputList[lenghtrand-1])
    time2 = time.clock()
    timeBi = time2 - time1
    ResultBi.append(timeBi*10**5)
    time1 = time.clock()
    Linear_Search(InputList, InputList[lenghtrand-1])
    time2 = time.clock()
    timeL = time2 - time1
    ResultL.append(timeL*10**5)


for i in range(15):
    if i != 0:
        time1 = time.clock()
        TowerOfHanoi(i, 'A', 'C', 'B')
        time2 = time.clock()
        timeH = time2 - time1
        ResultH.append(timeH*10**6)

plt.plot(ResultBi)
plt.plot(ResultBu)
plt.plot(ResultQ)
plt.plot(ResultH)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.show()

 

Revise this Paste

Your Name: Code Language: