link for file used as a referenced library https://drive.google.com/file/d/0B5sY
ID: 3935889 • Letter: L
Question
link for file used as a referenced library
https://drive.google.com/file/d/0B5sYndtQWKzSM3RfWjI0bFlPajA/view?usp=sharing
1. Create a class called MySortComparison and have it extend SortComparison.
2. In the main method, create a new instance of MySortComparison (using the no-arg
constructor) and call the executeAndWrite method.
3. Refresh your project.
4. Find the three text files that were generated - ascending.csv, descending.csv, and
random.csv.
5. Open each CSV (comma-separated value) file (your spreadsheet program should open it
by default) and inspect the results. The columns are array sizes. The values in the
middle of the table are elapsed execution run time in nanoseconds.
6. Note any patterns or major differences and discuss with a peer why the results are the
way they are when comparing the different algorithms with each other.
Part 2 - Implement the Sorting Algorithms
Tasks:
1. Start with Selection Sort.
2. In MySortComparison, override the corresponding sort method (selectionSort,
insertionSort, bubbleSort, mergeSort, or quickSort).
3. Write out the code that implements the sorting algorithm.
Explanation / Answer
To illustrate the dangers of macros, consider this naive macro
#define MAX(a,b) a>b?a:b
and the code
i = MAX(2,3)+five;
j = MAX(3,2)+5;
check this and consider what the fee after execution might be. The statements are turned into
int i = 2>3?2:3+5;
int j = 3>2?3:2+5;
thus, after execution i=eight and j=3 in preference to the expected end result of i=j=8! that is why you were recommended to use an additional set of parenthesis above, however regardless of these, the road is fraught with risks. The alert reader would possibly fast recognise that if a or b includes expressions, the definition must parenthesize every use of a,b in the macro definition, like this:
#define MAX(a,b) ((a)>(b)?(a):(b))
This works, furnished a,b don't have any aspect consequences. indeed,
i = 2;
j = 3;
k = MAX(i++, j++);
might result in ok=4, i=3 and j=5. this would be exceedingly unexpected to each person awaiting MAX() to behave like a feature.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.