Question: PROCESSING: You will perform the required sorted output of the matrix by two methods: Method 1 : Take all the ' r * c '
PROCESSING:
You will perform the required sorted output of the matrix by two methods:
Method :
Take all the rc elements in an array, sort it then output rowwise columnwise will also work! as a rc matrix.
Method :
Sort each row separately onebyone.
Then, sort each column separately onebyone.
Output this matrix.
MAKE SURE TO DO BOTH METHODS!!!
Sorting Method:
Use QuickSort.
Your program must have the following functions clearly identified and implemented:
The Comparison functions three functions to compare an element to another element:
EQa b : if a b return true, else return false.
LTa b : if a b return true, else return false.
GTa b : if a b return true, else return false.
Note that other operators can be computed by combining the NOT operator with the above three.
Each of the above three functions must increment a global counter 'comparisoncount' this will be needed for output
Obviously, one of your goals is to minimize the total number of element comparisons.
Absolutely no element comparisons outside these functions.
The Assignment function:
ASSIGNa b: assigns a b or a b
This function must increment a global counter 'assignmentcount' this will be needed for output
Note that a swap can be done by calling the assignment function three times.
Obviously, one of your goals is to minimize the total number of element assignments.
Absolutely no element assignments outside this function.
The PARTITION function.
The partitioning must be done InPlace.
For element comparisons and element assignments, you must use the above functions.
Integer comparisons like i n assignments like i or arithmetic like i need not be counted and can be done directly.
In addition, the Partition method written by you must make exactly:
ieright left in the variables used in lecture notes
element comparisons per call, for the actual partitioning.
Comparisons and Assignments you make for choosing a better pivot like median of elements are extra note that they should also be counted by 'comparisoncount' and 'assignmentcount'
The program should output the sorted matrix and output the total number of element comparisons and element assignments taken for each of the methods.
INPUT:
You can assume the elements will be of type 'double'.
Read the input matrix from a file named "input.txt
This file will have the matrix elements separated ONLY by "space" and "end of line newline characters.
The first line will have the number of rows and columns separated by space
Thereafter, each line will contain the elements of a row separated by space
You can assume each element value will be between and rounded to two decimal places, so that you can format the output correctly
For example:
Test your program with matrix of size ~ by
No other characters will be present in the file.
Note that your program must NOT take command line inputs.
OUTPUTS:
Your program will generate output files:
txt:
output the matrix for method keep same format as the input
output the total number of comparisons and assignments taken
txt:
output the matrix for method keep same format as the input
output the total number of comparisons and assignments taken
For example, mine will be sadasistxt and sadasistxt
Note that the output should be properly formatted like a matrix for easy readability.
Note that the input matrix shown above is NOT well formatted.
REPORT:
Write a report for the following in a file report.txt A simple text file or word document is good enough.
Write your observations on which method yields better lesser count. Compare them both theoretically ORDER of growth and practically the counts you get based on your testing
Also, does Method always give a correct output ie satisfies the objective given above If it does, then try to prove it Otherwise, try to provide a simple example where it doesn't work.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
