Python implementation of Binary Search
kw.py
Output: positive test
kodingwindow@kw:~$ python3 kw.py ——————————————————————————————————————————— Implementation of a Binary Search ——————————————————————————————————————————— How many numbers you want to enter 8 Enter Number 1 | -29 Enter Number 2 | 85 Enter Number 3 | -1024 Enter Number 4 | 2048 Enter Number 5 | 596 Enter Number 6 | 100 Enter Number 7 | 65535 Enter Number 8 | 0 Sorted numbers [-1024, -29, 0, 85, 100, 596, 2048, 65535] Enter the number to be searched 0 Element found at index 3 ——————————————————————————————————————————— kodingwindow@kw:~$ kodingwindow@kw:~$ python3 kw.py ——————————————————————————————————————————— Implementation of a Binary Search ——————————————————————————————————————————— How many numbers you want to enter 5 Enter Number 1 | 2 Enter Number 2 | 2 Enter Number 3 | 2 Enter Number 4 | 2 Enter Number 5 | 2 Sorted numbers [2, 2, 2, 2, 2] Enter the number to be searched 2 Element found at index 3 ——————————————————————————————————————————— kodingwindow@kw:~$
Output: negative test
kodingwindow@kw:~$ python3 kw.py ——————————————————————————————————————————— Implementation of a Binary Search ——————————————————————————————————————————— How many numbers you want to enter 5 Enter Number 1 | 8 Enter Number 2 | 5 Enter Number 3 | 2 Enter Number 4 | # Invalid Input! Program Terminated ——————————————————————————————————————————— kodingwindow@kw:~$ kodingwindow@kw:~$ python3 kw.py ——————————————————————————————————————————— Implementation of a Binary Search ——————————————————————————————————————————— How many numbers you want to enter 0 Please enter a positive integer ——————————————————————————————————————————— kodingwindow@kw:~$
What Next?
Sorting Algorithms
Advertisement