Example #1
0
from com.bridgelabz.util.utility import Utility

utility_obj=Utility()

list=Utility.binarysearch_wordlist()
print("These are the list of items we have in our list\n")
for i in list:
    print(i,end=" ")

print("\n\nEnter word you are looking for")
search_item=Utility().get_string()
search_item_index=Utility.binary_search_for_string(list,search_item)
if search_item_index != -1:
    print(str(list[search_item_index]) + "  index => " + str(search_item_index))
Example #2
0
#######################################Binary Search for String#######################################################

if (choice == 2):
    print("Enter number of elements you want to put in list")

    list_str_size = utility_obj.get_int()
    store_user_value = []
    print("Now enter all elements")
    for i in range(0, list_str_size):
        store_user_value.append(utility_obj.get_string())

    print("Enter which element you are looking for")
    search_item = utility_obj.get_string()

    start_time = (time.time() * 1000 * 1000)
    search_item_index = Utility.binary_search_for_string(
        store_user_value, search_item)
    end_time = (time.time() * 1000 * 1000)
    binary_search_for_string = ''
    execution_time[binary_search_for_string] = (end_time - start_time)
    if search_item_index != -1:
        print(
            str(store_user_value[search_item_index]) + "  index => " +
            str(search_item_index))

#######################################Insertion sort for Integer######################################################

if (choice == 3):
    print("Enter number of elements you want to put in list")
    list_int_size = utility_obj.get_int()
    print("Now enter all elements")
    store_user_value = []