


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Internal and external sorting - Correct Answers -What are the two types of sorting? the number of comparisons of keys AND the number of times entries must be moved inside a list - Correct Answers -What are the two major factors used to evaluate the performance of a sorting algorithm? internal sorting - Correct Answers -records to be sorted are kept in RAM external sorting - Correct Answers -records are kept in external files on disks, tapes, or other secondary storage devices The performance of a sorting algorithm is closely related to the ... - Correct Answers - underlying data structure of a list (algorithm should be aware of the implementation of the list - preferable to implement the sorting algorithm as a method of the list class [sortable list]} when the list is already in sorted order (only n - 1 comparison of keys) - Correct Answers -The best case for contiguous insertion sort occurs... when the list is in reverse order - Correct Answers -The worst case for contiguous insertion sort occurs... Selection sort is more suitable for long contiguous list than insertion sort - Correct Answers -In what situation may you select selection sort over insertion sort? It is easy to implement. - Correct Answers -What is the advantage of bubble sort? numbers that are multiples of each other - Correct Answers -When Shell sort is used, what types of increments should you avoid? quicksort - Correct Answers -best: O(n lg n) avg: O(n lg n) worst: O(n^2) idea: partition the list using some chosen key called the pivot (those less than pivot in one sublist, those greater in another); sort separately and merge at the end
radix sort - Correct Answers -best: O(nk) avg: O(nk) worst: O(nk) idea: consider the partial key (on character at a time) and divide the entries into many sublists based on one character from the key 1; It becomes an ordinary insertion sort to make certain that the list is completely in order - Correct Answers -Which number should always be used as the last increment in Shell sort? Why? Shell sort requires random access in the list which is not well supported by linked implementation. - Correct Answers -Why is Shell sort not suitable for linked implementation? Shell sort really is insertion sort optimized by the preprocessing stage of first sorting sublists using larger increments - Correct Answers -Briefly explain why Shell sort is much faster than insertion sort. divide-and-conquer sorting - Correct Answers -divide the list into two roughly equal- sized lists and sort them separately; the two short sublists are then combined together mergesort and quicksort - Correct Answers -What are the two typical sorting algorithms that use the divide-and-conquer idea? For linked implementation, the merge sort is very efficient. It uses space efficiently and significant less time is needed to locate the center of the linked list - Correct Answers - What type of implementation is more suitable for mergesort, contiguous or linked? Why? What is the pivot in quicksort? - Correct Answers -A key chosen that will help partition the list Choose a pivot near the center of the list in the hopes that the choice will have (roughly) half the keys on each side; optimized quicksort??? - Correct Answers -What kind of a pivot would be ideal for quicksort? Which entry in a list is usually chosen as the pivot in real applications? optimized quicksort - Correct Answers -use two indices move from both ends of the list toward the center; perform a swap only when a large key is found by the low index and a small key by the high index Quicksort in the worst case is the worst case of both insertion and selection sorts - in reverse order - Correct Answers -When does the worst case time complexity occur for contiguous quicksort?
k-way mergesort - Correct Answers -best: O(n lg n) avg: O(n lg n) worst: O(n lg n) idea:assume list sorted in a tape; assume we have k total number of tapes available; read M entries one at a time from input table, store internally into the RAM; then write the sorted list to one of the tapes Shell sort - Correct Answers -best: O(n lg n) avg: O(n^2) worst: O(n log^2 n) idea: It first compares and sorted the entries far apart; afterward, the entries closer together are sorted; finally the increment between keys being compared is reduced to 1