Пример #1
0
__author__ = 'Egbert'

import ordsearch

print(ordsearch.linear([1,2,3,4,5,6,7,8,9,10], 4))
print(ordsearch.linear([1,2,3,5,6,7,8,9,10], 11)) #zit de 4 niet in
print(ordsearch.linear([3,1,7,4,6,1,4,6,7], 4)) #niet geordent
#print(ordsearch.linear([1,2,3,"vier",5,6,7,8],9))

print("------------ BINARY SEARCH --------------")

print(ordsearch.binary([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20], 4))

Пример #2
0
__author__ = 'Egbert'

from ordsearch import binary
from ordsearch import linear
from util import lines
import searchmeasure


print(binary(lines("Unabr.dict"),"eagle"))
print(binary(lines("Unabr.dict"),"zygose"))

searchmeasure.search("Unabr.dict","eagle")
Пример #3
0
# ask for the first word
value = input("Search for first word? ")
# continue as long as a word was typed
while value != "":
    # measure time for linear searching
    lstart = time.process_time()
    lresult = linear(words, value)
    lend = time.process_time()
    # time values are fractions of seconds;
    # multiply by a million and round to get microseconds
    ltime = round((lend - lstart) * 1000000)

    # measure time for binary searching
    bstart = time.process_time()
    bresult = binary(words, value)
    bend = time.process_time()
    # time values are fractions of seconds;
    # multiply by a million and round to get microseconds
    btime = round((bend - bstart) * 1000000)

    # print the outcome
    if (lresult != bresult):
        print("results for linear and binary differ: {} versus {}".format(
            lresult, bresult))
    elif (lresult < 0):
        print("'{}' does not occur".format(value))
    else:
        print("'{}' occurs at position {}".format(value, lresult))
    # print the measured time
    print("linear search took {} micros to complete".format(ltime))
Пример #4
0
__author__ = 'Egbert'

from sort import bubble
from sort import merge
from util import words
from ordsearch import binary

#print(bubble([3,253,223,52,6,23,6,2,6,8,3,5,34,8,3,433,76,83465,8,34,36,457,5478,3,45,2]))
#print(bubble(words("hacktest.txt")))
#print(bubble(words("Unabr.dict")))

#print(merge([3,253,223,52,6,23,6,2,6,8,3,5,34,8,3,433,76,83465,8,34,36,457,5478,3,45,2]))
#print(merge(words("hacktest.txt")))
#print(merge(words("Unabr.dict")))

print(binary(merge(words("grail.txt")),"swallow"))