From 3841d453c5f73caed1832baa36c6ee3d056099d1 Mon Sep 17 00:00:00 2001 From: Vignesh P <60399486+Senku01@users.noreply.github.com> Date: Sat, 1 Oct 2022 20:52:23 +0530 Subject: [PATCH] Created a Binarysearch.py This Program Is used to Search elements of an Array Using Binary Search Algorithm and Runes with Time Complexity of O (Log n) Space Complexity of O(1) --- Search Algorithms/binarysearch.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Search Algorithms/binarysearch.py diff --git a/Search Algorithms/binarysearch.py b/Search Algorithms/binarysearch.py new file mode 100644 index 0000000..30668fc --- /dev/null +++ b/Search Algorithms/binarysearch.py @@ -0,0 +1,29 @@ +#This code is Contributed by @Senku01 +# Time Complexity O(log N) +# Space Complexity O(1) + +#As per Doc + +def condition(cards,query, mid): + mid_num = cards[mid] + if mid_num == query: + if mid_num-1>=0 and cards[mid-1] == query: + return 'left' + else: + return 'right' + elif mid_num