13080 - Binary Search   

Description

 

Given a sorted array and a key. Find whether or not the key is in the array. If yes, output its location. If not, print "Not found". Input format is as follows:

 

Input Case:

7

1 3 5 7 8 10 11

5

 

Explanation:

In which, 7 stands for the length of the array and 5 stands for the key. You are to determine whether the key appears in the array or not. An example shows the concept of Binary Search as below:

Binary Search Algorithm - Java Program Of Binary Search Algorithm

Also, we have provided the partial judge code (13080.c) below for you. All you need to do is complete the int binarySearch(int *sortedarr, int start, int end, int key) function and submit it to NTHU Online Judge System.

int binarySearch(int *sortedarr, int start, int end, int key){

             ...

             ...

}

 

(Figure Reference Link: https://codenuclear.com/binary-search-algorithm/)

Input

Given the length of the sorted array.

Then followed by the elements of the sorted array.

Finally, given the key that you wanna find its location.

 

Output

Print the location of the key.

 

Sample Input  Download

Sample Output  Download

Partial Judge Code

13080.c

Partial Judge Header

13080.h

Tags




Discuss