Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this I have to practice using Linear Search and Binary Search. Can you help me compose a program that prompts the user to enter

For this I have to practice using Linear Search and Binary Search. Can you help me compose 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.

Use C# coding please

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

0|1|2|3|4|5|6|7|8|9|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|125|129|311|333|361|402|412|475|499|501|

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions