JAVA CODE THANK YOU 2. Binary Search by CodeChum Admin Searching is one very important Computer Science task. When you have a list, searching is natural. You would want to search for an item in the list. If the list is not sorted, there is no way to it but do a linear search - check each element until the item is found or until there are no elements left to inspect.   But when the list is sorted, searching becomes way faster! Think of the dictionary; the actual printed dictionary. The words there are sorted from A-Z. And searching for what soliluquy means you should not start from A and turning the pages one by one until you reach the entries for the letter S.   What do you usually do? You open the dictionary right smack in the middle and see if you are in the letter S. If you are short and are brought to a letter before S, you try to estimate and open a page to the right of where you are currently. If you went beyond S, you try to open a page before the page you are currently at.   This is called Binary Search.   You are going to use the List to store the numbers. Sort the list via Collections.sort(). It is used as shown below:   List list = new LinkedList(); list.add(19); list.add(8); list.add(3); list.add(11); list.add(15);   Collections is found in the java.util package. Input The first line contains a positive integer n that represents the number of items there are. The second line contains the n numbers. The third line contains one last number which is the search item: the item that needs to be searched in the list. 10 1·2·3·4·5·6·7·8·9·10 7 Output The numbers should be stored in a list and should be sorted. Print the sorted items in one line. And in a line that should follow, print the count of iterations it took for the binary search to finish. And finally, print whether the search item is "FOUND" or "NOT FOUND". 1·2·3·4·5·6·7·8·9·10 4·FOUND

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

JAVA CODE THANK YOU

2. Binary Search

by CodeChum Admin

Searching is one very important Computer Science task. When you have a list, searching is natural. You would want to search for an item in the list. If the list is not sorted, there is no way to it but do a linear search - check each element until the item is found or until there are no elements left to inspect.

 

But when the list is sorted, searching becomes way faster! Think of the dictionary; the actual printed dictionary. The words there are sorted from A-Z. And searching for what soliluquy means you should not start from A and turning the pages one by one until you reach the entries for the letter S.

 

What do you usually do? You open the dictionary right smack in the middle and see if you are in the letter S. If you are short and are brought to a letter before S, you try to estimate and open a page to the right of where you are currently. If you went beyond S, you try to open a page before the page you are currently at.

 

This is called Binary Search.

 

You are going to use the List to store the numbers. Sort the list via Collections.sort(). It is used as shown below:

 

List <Integer> list = new LinkedList<Integer>(); list.add(19); list.add(8); list.add(3); list.add(11); list.add(15);

 

Collections is found in the java.util package.

Input

The first line contains a positive integer n that represents the number of items there are. The second line contains the n numbers. The third line contains one last number which is the search item: the item that needs to be searched in the list.

10 1·2·3·4·5·6·7·8·9·10 7

Output

The numbers should be stored in a list and should be sorted. Print the sorted items in one line. And in a line that should follow, print the count of iterations it took for the binary search to finish. And finally, print whether the search item is "FOUND" or "NOT FOUND".

1·2·3·4·5·6·7·8·9·10 4·FOUND
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY