Question: In C#, compare the performance of the sequential search algorithm and the binary search algorithm. Firstly, you need to create a sorted array having 4999

In C#, compare the performance of the sequential search algorithm and the binary search algorithm. Firstly, you need to create a sorted array having 4999 integers. The values of these integers can be, for example, from 1 to 4999. Then, add a new private Integer data member named compCount that is initialized to 0. In each of the search algorithms, add a line of code right after the critical comparison is made that increments compCount by 1. 

(1). Run both methods in C#, searching for the following numbers: 

 the smallest number in the array, say 1; 

 the largest number, say 4999; 

 the median number, say 2500. 

(2). Compare the values of compCount after running both methods. That is, when searching the smallest number, the largest number, and the median number in the array, your C# code should have the output answering the following two questions:

 What is the value of compCount for each method? 

 Which method makes the fewest comparisons?

Step by Step Solution

3.54 Rating (168 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

using System using System CollectionsGeneric using System Ling using System Text using System Manage... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (2 attachments)

PDF file Icon

635dfd53a88ea_180547.pdf

180 KBs PDF File

Word file Icon

635dfd53a88ea_180547.docx

120 KBs Word File

Students Have Also Explored These Related Accounting Questions!