이분탐색

    Python 이분탐색 알고리즘 활용

    Python 이분탐색 알고리즘 활용 shop_menus = ["만두", "떡볶이", "오뎅", "사이다", "콜라"] shop_orders = ["오뎅", "콜라", "만두"] def is_available_to_order(menus, orders): shop_menus.sort() # 정렬 for order in orders : # order를 orders에서 하나하나 뽑아서 밑에있는 이분탐색 함수를 돌려보면 될 것 if not is_existing_target_number_binary(order, shop_menus): # 하나라도 존재하지 않는다면 return False return True ## 이분탐색의 코드 def is_existing_target_number_binary(target, arr..

    Python 이진탐색 알고리즘

    Python 이진탐색 알고리즘 1~100 사이에서 숫자 하나를 맞춰야 한다면 알고리즘의 관점에선 가장 효율적인 방법은 범위의 절반인 50을 시도해보는 것이다. 대답이 UP이라면 1~49는 후보에서 없어지고, 대답이 DOWN이라면 51~100이 후보에서 없어지기 때문이다. 이러한 방법을 이진탐색이라 한다. finding_target = 14 finding_numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] def is_existing_target_number_binary(target, array): current_min = 0 current_max = len(array) -1 current_guess = current_min + curren..