-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Divide and conquer algorithms", exercise 3 #30
Comments
The code is longer than expected, but it seems to work properly.
|
|
|
|
The output of the five test cases is always Here is the script:
|
Just a simple note: as explained in the previous lecture, quicksort is an algorithm that modifies the input list in place, meaning that you should not create sublists from the input list but rather directly modify the input list. Try to run it with Python Tutor and see what is happening. |
|
Implement the divide and conquer quicksort algorithm in Python – i.e. the recursive
def quicksort(input_list, start, end)
. First, it takes a list and the positions of the first and last elements to consider as inputs. Then, it callspartition(input_list, start, end, start)
(defined in the previous exercise) to partition the input list into two slices. Finally, it executes itself recursively on the two partitions (neither includes the pivot value since it has already been correctly positioned through the partition execution). In addition, define the base case of the algorithm appropriately to stop if needed before running the partition algorithm. Accompany the implementation of the function with the appropriate test cases. As supporting material, Fekete and Morr released a nonverbal definition of the algorithm [Fekete, Morr, 2018c], which is helpful to understand the rationale of the binary search steps.The text was updated successfully, but these errors were encountered: