Array Class: BinarySearch, Sort methods

advertisement
Array Class: BinarySearch, Sort methods
Use the Visual Studio.Net documentation to pull up the Help page for the
.Net Framework Class Library's Array class. You might want to look through the
methods, but focus specifically on the BinarySearch method, and the Sort
method. Using the code samples given in the help files, create a short C#
application (Console application is fine) that will demonstrate both of these builtin methods.
Optional Extra Step:
If you feel comfortable implementing IComparable (or IComparer), then
you should be able to create an comparison method that also increments a
counter, in order to keep track of the number of comparisons that have been
made. You can do this using a global variable (well, a class static variable, but
those two things are almost the same  ).
Answer the following questions (type them into this Document, and save
this document somewhere for future reference):
What is the expected (average) running time for the Sort method? Using
a calculator (or Maple, or Excel, etc), create a table of data, assuming that the
Sort method would be used to sort arrays of the size listed below.
What is the maximum (worst-case) running time for the Sort method?
Using a calculator (or Maple, or Excel, etc), create a table of data, assuming that
the Sort method would be used to sort arrays of the size listed below.
Size of the array
Expected Number of
swaps
100
400
900
1600
2500
3600
How does the built-in Sort method compare to BubbleSort and
SelectionSort?
Download