Question: Define a function force _ sort ( l ) that takes as input a list of integers l and outputs a list of the same

Define a function force_sort(l) that takes as input a list of integers l and outputs a list of the same integers in sorted order. The function should use a brute-force sorting algorithm, meaning that it generates permutations of the initial list until it finds a permutation that is sorted. You should write code to generate permutations yourself (do not use library functions for that). Write a separate function check_sorted(l) that returns True if and only if the input list is sorted.
def check_sorted(l):
# YOUR CODE HERE
return True
def force_sort(l):
# YOUR CODE HERE
return []
# This call should return [-1,3,5,9,13].
print(force_sort([9,13,-1,5,3]))
# This call should return False.
print(check_sorted([-1,3,13,5,9]))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!