Question:
Some teams qualified for the 2014 World Cup. The score of the teams were stored in an array in sorted order and array index is the represents the team. Index 0 represents the Team 1; index 1 represents the Team 2 and so on. If a score is given, then should find out which team got that score with a O(log(n)) time.
Since Ram wanted to solve this puzzle with binary search and he decided to write binary search himself. But he cannot remember the logic of binary search . Help Ram to write the program.
Note:
Create the main() inside the class ‘BinarySearch‘
Function signature : public static int binarySearch(int[] ar,int size,int key)
Input and Output Format:
Refer sample input and output for formatting specifications.
Sample Input and Output 1:
Enter the number of Teams:
5
Enter the score:
12
16
23
45
67
Enter the score to be searched:
23
23 is the score of Team 3
Sample Input and Output 2:
Enter the number of Teams:
4
Enter the score:
12
34
45
77
Enter the score to be searched:
59
Score Not Found
CODE:–
BinarySearch.java
Tags:
binary tree | linear data structure | data structures in c | data structure | heap sort | abdul bari udemy
data structures udemy | coding ninjas data structures | binary tree example | data structure and algorithmic thinking with python | queue geeksforgeeks | data structures in java programming
ConversionConversion EmoticonEmoticon