Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please code in java Lab8B: For this part of the lab, you will practice using Linear Search and Binary Search. Please review the lecture slides

image text in transcribed

please code in java

Lab8B: For this part of the lab, you will practice using Linear Search and Binary Search. Please review the lecture slides and try to re-code them. The goal of this lab is for you to perform these two searches and visualize the behavior. For this first part of the lab, write a program that prompts the user to enter 15 numbers in sorted order (meaning the user enters them in ascending order). Store the inputted numbers into a 1D array of size 15. Then, ask the user for a number to search for in the array (i.e. the "target). Now, print the array. Next, use Linear Search to search the array. Print out each of the indices (or "indexes") that are being examined until the algorithm finds the target. Finally, use Binary Search to search the array. Print out each of the indices (or "indexes) that are being examined until the algorithm finds the target. Note: After the "target" is entered by the user, the program needs to print 1) the array, 2) the indices of a linear search and 3) the indices of a binary search. Your output should look like the sample output below. User input is in bold. Sample output #1 Enter slot 0 : 0 Enter slot 1: 1 Enter slot 2: 2 Enter slot 3: 3 Enter slot 4: 4 Enter slot 5: 5 Enter slot 6: 6 Enter slot 7: 7 Enter slot 8: 8 Enter slot 9: 9 Enter slot 10: 10 Enter slot 11: 11 Enter slot 12: 12 Enter slot 13: 13 Enter slot 14: 14 Enter a target: 15 0111213141516171819|10|11|12|13|14|| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 7 11 13 14 Sample output #2 Enter slot 0 : 3 Enter slot 1: 11 Enter slot 2: 45 Enter slot 3: 57 Enter slot 4: 81 Enter slot 5: 125 Enter slot 6: 129 Enter slot 7: 311 Enter slot 8: 333 Enter slot 9: 361 Enter slot 10: 402 Enter slot 11: 412 Enter slot 12: 475 Enter slot 13: 499 Enter slot 14: 501 Enter a target: 402 3|11|45|57|81|12512913111333361402412475499501|| 0 1 2 3 4 5 6 7 8 9 10 7 11 9 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions