Question: Haskell Language A sorting network is a comparator network where the final values on the wires are indeed always sorted (smaller numbers towards the top),
Haskell Language
A sorting network is a comparator network where the final values on the wires are indeed always sorted (smaller numbers towards the top), no matter what initial values we start with. The zero-one principle discussed in the CLR chapter states that it is enough to make sure a comparator network with n wires always correct sorts lists of 0s and 1s. The more general case, where it sorts lists of numbers 1 through n, follows from correctly sorting lists of 0s and 1s. For this problem, you have to write code to test whether or not a comparator network is a sorting network. By the zero-one principle, it suffices to test your network on all possible sequences of 0s and 1s. The command-line for this part is Sorting filename Print out True if the comparator network in the given file is a sorting network, and False otherwise. There is a public test to check that your program prints True for sort1.txt.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
