Skip to content
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

Assignment 4 - Quicksort #34

Open
gmertk opened this issue Dec 22, 2015 · 4 comments
Open

Assignment 4 - Quicksort #34

gmertk opened this issue Dec 22, 2015 · 4 comments

Comments

@gmertk
Copy link
Owner

gmertk commented Dec 22, 2015

The most famous sorting algorithm. Invented by Tony Hoare. There is a short interview with him telling his invention of quicksort. Read more about quicksort. We will go over two approaches here. First one is the real implementation of quicksort. Second one is less efficient but functional implementation with filters.

git checkout assignment004 to start.

  1. Quicksort In-place
    • Implement Lomuto's partition algorithm. Remember that you need to guard swap from swapping a location with itself.
    • Implement Hoare's partition algorithm. Note that if you follow the pseudo code given in Wikipedia, the pivot's final location might not be at the returned index. You can check Sedgewick's Algorithms book for another version. Add more tests when you are done with your implementation.
    • By using your hoarePartition, implement an in-place quicksort.
    • Read about the Dutch National Flag problem. Your function takes a pivot's index. It should rearrange the elements such that all elements less than pivot come first, followed by elements equal to pivot, followed by elements greater than pivot.
    • You can check out how Swift implements sort. The file is a GYB template which stands for Generate Your Boilerplate. You need to clone the Swift repo, and run ./utils/gyb on the Sort.swift.gyb to convert it to actual Swift source code. As you can see, the function is called introSort, a hybrid sorting algorithm where quicksort falls back to insertion sort and heap sort.
  2. Functional quicksort
    • This is a rather inefficient but neat solution. Pick a pivot and remove it from the array. Then use filter to create two arrays: one containing smaller items than the pivot, other one containing the rest. Then call the function on these arrays, and append them to each other with the pivot in the middle.

Due date: 27.12.2015

@diegopetrucci
Copy link

The wiki redirects to the shell sort page instead of this one https://en.m.wikipedia.org/wiki/Quicksort

@gmertk
Copy link
Owner Author

gmertk commented Dec 22, 2015

Fixed now, thanks Diego!

@diegopetrucci
Copy link

I feel something is wrong with the issue. Maybe playground formatting? I get this when I open it:

schermata 2015-12-24 alle 12 07 58

@gmertk
Copy link
Owner Author

gmertk commented Dec 24, 2015

Yep, updated it to show the rendered format.

I guess it happened because I did the previous link fixing on github editor. Thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants