For this assignment, you are to implement a number of common sorting algorithms in Lisp. The primary purpose of this assignment is to use these common algorithms to get you think in Lisp. Simply going out on the Internet and finding the solutions won't help you to think in Lisp. So please don't do that. You may work in groups of two on this assignment. Hopefully, each of you will help the other to think in Lisp.
You are to write the functions using the names specified:
Remember that Insertion Sort works by starting with a new empty list and inserting the elements from the original list one at a time into the new list in sorted order.
Selection sort works by finding the smallest element in the list and placing that into the first position of the list. Then it finds the second smallest element and places that into the second position in the list.
Quicksort works by first selecting a pivot point from the list (often this is just the first value in the list). Then two list are created from the remaining elements in the list: those values less than the pivot point and those value greater than or equal to the pivot point. The quicksort algorithm is then called on these two new lists. The lists returned are joined together with the pivot point to create a new list and this new list is returned. If the list given to the quicksort function has one or zero elements, that list is returned immediately.
Mergesort works by first dividing a list into two halves (or nearly equal parts - if there is an odd number of members of the list the first "half" will have one more member than the second "half"). The mergesort algorithm is called on each of these halves. If the list sent to mergesort has one element, that list is returned immediately. The two lists that are returned from the recursive calls are then merged together into one new list. This new list is then returned by the mergesort function.
Each function should require a single input argument, which is a list of numbers. You can assume there are only numbers in the input list, i.e., no error checking is required. The output should be a list containing the same numbers, sorted in ascending order.
Lisp works best when there are a number of small functions that are used together to solve the problem instead of trying to write one big function. For example, when writing selection sort, we may want one function that will find the smallest value in a list and another function to remove the smallest value in a list (or to remove a specific value from a list). Using these functions, a recursive call to selectsort and a list joining function should be sufficient to write the selection sort algorithm in lisp.
Don't forget to put comments in your code.
Try to make your code as purely functional as possible. In particular, avoid defining variables (e.g., "setf" and "setq"), and avoid iteration ("do"). Use functions instead of variables, and recursion instead of iteration.
turnin -c cs476 -p hw2 hw2.lisp README
You may work on this project by yourself or in a group of two. If you work on this with another member of the class, only submit your project once using turnin. Be sure that you clearly state in your README file the names and NETIDs of both members in the group.