IN C PROGRAMMING Sample Cumulative Question #1 Note: The following problem is ex
ID: 3716545 • Letter: I
Question
IN C PROGRAMMING
Sample Cumulative Question #1 Note: The following problem is excerpted from a final exam I gave in Fall 2017. Based on the average score, I would say this was [unintentionally] one of the more difficult wildcard questions I've given 6. (10 pts) (Wildcard) Suppose someone develops a new algorithm for sorting integers, and that person uses the following process to test whether that algorithm actually works 1. Generate a randomly populated array 2. Call the sorting algorithm on that array 3. Call an isSortedO function on that array to check whether it is sorted. To do this, the function loops through the array and checks that array[i] is less than or equal to array[i+1] for each valid index in the array, being careful not to go out of bounds at the end of the array. The function returns 1 if the array passes all those checks (because that means the array is sorted), and returns 0 otherwise 4. Repeat steps 1 through 3 millions of times, with many different input arrays. You can assume that this person is generating a very good range of test cases in Step #1. (Eg, assume this person has tested many arrays of length 0, 1, 2, and 3; large arrays; small arrays; arrays that are even in length; arrays that are odd in length; arrays that contain only positive integers; arrays that contain only negative integers; arrays that contain both positive and negative integers; arrays that do and do not contain zero; arrays with and without duplicate values; arrays that are already sorted in non-decreasing order; arrays that are sorted in non-increasing order; and so on.) You can also assume that this person has a solid function for step 3 of the process that has been thoroughly vetted and is free of bugs. That function will return 1 if it receives a sorted array and 0 if it receives an unsorted array. You can also assume this person is calling that function correctly and is passing that function the same array that is getting passed to the sorting function that is being tested. Ignoring the fact that this process could take a lot of time, is this a reliable methodology for testing the sorting algorithm? In other words, if this process terminates without ever finding an unsorted array in step 3, can we say with fairly high confidence that this new sorting function works, or is there some critical flaw or oversight in this process? If you think there is a flaw in this methodology, clearly (and briefly) explain what that flaw is. If you think this methodology is sound, simply write "Hooray!" as your answer to this problem.Explanation / Answer
I can say hooray !!
This is enough for testing a sorting algorithm, anyhow I will add some more test cases like:
1) while the input array has maximum allowed value in allowed range
2) while the input array has greater than maximum allowed value in allowed range
3) while the input array has minimum allowed value in allowed range
4)while input array has lesser than minimum allowed value in allowed range
5) If input array has float values, both float and integer values
Manual checking:
1) you sort the input array on your own and check it with the result array generated
2) input and output array should be in same size
3) All the elements of the inut array must be present in the sorted array