Design and code a python solution for the problems. You must come up with your own algorithm and the honor code applies (no references).
It is strongly recommended that you followthese problem solvingsteps to help you find a correct and efficient algorithm, but you are not required to submit them.
Problem 1[50 points] Design an algorithm that will efficiently find the largest difference between any two elements (not necessarily adjacent) in a list of numbers. Submit a python functionmax_difference(values)that returns the maximum difference as a number. **You may assume there will be at least 2 elements in the list.
Problem 2[50 points] Suppose you are given a list of N values, each of which is either a 0 or a 1, initially arranged in random value. You need tomodify the values in the list in situ(don't use another list)so that it consists of a sequence of 0s (possibly empty) followed by a sequence of 1s (also possibly empty), with the same number of both as were originally in the list. For example:0111010010 -> 00000111111000111000 -> 00000011110000000000 -> 0000000000This problem could be solved by any of the common sorting algorithms, but the special nature of the values in the list makes it possible to devise a particularly efficient solution. (Here, efficiency would refer partly to how many times you need to reset a value in the list, and partly to how many times you would have to change list position variables in your algorithm.) Design an efficient algorithm and submit it as a python functionsort_bivalued(values)that returns the sorted list.
0111010010 -> 00000111111000111000 -> 00000011110000000000 -> 0000000000
len
range
print(max_difference([1,2,3,4,5])
**Note: WebCAT doesnottest for your efficiency. Getting full points on WebCAT doesnotguarantee you will receive full points for efficiency.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here