Example #1
0
def count_searches(value, ordered_array, total_time):
    start = time()
    cont = 0
    while True:
        cont += 1
        binary_search(value, ordered_array)
        sequential_search(value, ordered_array)
        end = time()
        total = end - start
        if total_time <= total:
            break
    return cont
    def test_sequential_search_not_found(self):
        # testcase
        arr = [1, 2, 3, 5, 7, 10]
        n = 4

        # expected
        expected = -1
        self.assertEqual(sequential_search(arr, n), expected)
    def test_sequential_search_basic(self):
        # testcase
        arr = [1, 2, 3, 5, 7, 10]
        n = 5

        # expected
        expected = 3
        self.assertEqual(sequential_search(arr, n), expected)
Example #4
0
 def test_empty(self):
     self.assertEqual(sequential_search([], 3), False)
Example #5
0
 def test_one_true(self):
     self.assertEqual(sequential_search([3], 3), True)
Example #6
0
 def test_many_false(self):
     self.assertEqual(sequential_search([2, 4, 7, 6, 3], 5), False)
Example #7
0
 def test_many_true(self):
     self.assertEqual(sequential_search([2, 4, 7, 6, 3], 6), True)
Example #8
0
 def test_one_false(self):
     self.assertEqual(sequential_search([4], 3), False)
Example #9
0
def analisa_tempo():

    size_list = 10000

    result_binary = []
    result_indexed = []
    result_sentinel = []
    result_simple = []

    i = 0

    while i <= 50:

        lista = []
        insere_elementos_desordenados(size_list, lista, size_list**2)
        quick_sort(lista, 0, len(lista))

        # element = random.randint(0, size_list**2)
        element = lista[-1]

        # ord_start = time.time()
        # ord_stop = time.time()
        #
        # ord_res = ord_stop - ord_start

        start = time.time()
        binary_search(lista, element)
        stop = time.time()

        elapsed = stop - start  # + ord_res

        result_binary.append(elapsed)

        start = time.time()
        indexed_search(lista, element, size_list)
        stop = time.time()

        elapsed = stop - start  # + ord_res

        result_indexed.append(elapsed)

        list = lista
        list.append(element)

        start = time.time()
        sentinel_sequential(list, element)
        stop = time.time()

        elapsed = stop - start

        result_sentinel.append(elapsed)

        start = time.time()
        sequential_search(lista, element)
        stop = time.time()

        elapsed = stop - start

        result_simple.append(elapsed)

        i += 1

    plota_grafico(result_binary, result_indexed, result_sentinel,
                  result_simple)

    return
Example #10
0
from sequential_search import sequential_search

import random

y = []
for i in range(1,1000):
    y.append(i)

times=0
    
import time
for i in range(10000):
    times=i
    x= random.randint(1,1000)
    a=0
    start = time.time()
    binary_search(y,x)
    end = time.time()
    time_interval = end - start
    a=time_interval+a

    b=0
    start = time.time()
    sequential_search(y,x)
    end = time.time()
    time_interval = end - start
    b=b+time_interval
    
print('bin',a)
print('seq',b)