当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

西安建筑科技大学:《数据结构与算法》课程教学资源(PPT电子教案)第四部分 查找、排列_排列 Chapter 8 SORTING(英文)

资源类别:文库,文档格式:PPT,文档页数:50,文件大小:826.5KB,团购合买
1. Introduction and Notation 2. Insertion Sort 3. Selection Sort 4. Shell Sort 5. Lower Bounds 6. Divide-and-Conquer Sorting
点击下载完整版文档(PPT)

Chapter 8 SORTING 1 Introduction and Notation 2. Insertion Sort I3 Selection Sort 4. Shell Sort 5. Lower Bounds 6. Divide-and-Conquer Sorting

Chapter 8 SORTING 1. Introduction and Notation 2. Insertion Sort 3. Selection Sort 4. Shell Sort 5. Lower Bounds 6. Divide-and-Conquer Sorting

Chapter 8 SORTING(continue) 7. Mergesort for Linked Lists 8. Quicksort for Contiguous Lists 9. Heaps and Heapsort I10. Comparison of Methods 1 1. Pointers and pitfalls

Chapter 8 SORTING (continue) 8. Quicksort for Contiguous Lists 9. Heaps and Heapsort 10. Comparison of Methods 11. Pointers and Pitfalls 7. Mergesort for Linked Lists

8.1 Introduction and notation 9In an external sort there are so many records to be sorted that they must be kept in external les on disks, tapes, or the like. In an internal sort the records can all be kept internally in high-speed memory. We consider only internal sorting. We use the notation and classes set up in Chapters 6 and 7. thus we shall sort lists of records into the order determined by keys associated with the records. The declarations for a list and the names assigned to various types and operations will be the same as in previous chapters

8.1 Introduction and notation ◆In an external sort, there are so many records to be sorted that they must be kept in external les on disks, tapes, or the like. In an internal sort the records can all be kept internally in high-speed memory. We consider only internal sorting. ◆We use the notation and classes set up in Chapters 6 and 7. Thus we shall sort lists of records into the order determined by keys associated with the records. The declarations for a list and the names assigned to various types and operations will be the same as in previous chapters

C To analyze sorting algorithms, we consider both the number of comparisons of keys and the number of times entries must be moved inside a list, particularl in a contiguous list Both the worst-case and the average performance of a sorting algorithm are of interest. To find the average, we shall consider what would happen if the algorithm were run on all possible orderings of the list with n entries, there are n! such orderings altogether and take the average of the results

◆To analyze sorting algorithms, we consider both the number of comparisons of keys and the number of times entries must be moved inside a list, particularly in a contiguous list. ◆Both the worst-case and the average performance of a sorting algorithm are of interest. To find the average, we shall consider what would happen if the algorithm were run on all possible orderings of the list (with n entries, there are n! such orderings altogether) and take the average of the results

Sortable lists To write efficient sorting programs, we must access the private data members of the lists being sorted Therefore, we shall add sorting functions as methods of our basic List data structures the augmented list structure forms a new adt that we shall call a Sortable List with the following form template class sortable list: public List<Record i public: / Add prototypes for sorting methods here. private: / Add prototypes for auxiliary functions here

Sortable Lists ◆To write efficient sorting programs, we must access the private data members of the lists being sorted. Therefore, we shall add sorting functions as methods of our basic List data structures. The augmented list structure forms a new ADT that we shall call a Sortable_List, with the following form. template class Sortable_list:public List { public: // Add prototypes for sorting methods here. private: // Add prototypes for auxiliary functions here. };

Hence a Sortable list is a list with extra sorting methods The base list class can be any of the List implementations of Chapter 6. We use a template parameter class called Record to stand for entries of the sortable list C Record objects can be compared to each other or to a Key by first converting the record objects to their

◆Hence a Sortable_list is a List with extra sorting methods. ◆The base list class can be any of the List implementations of Chapter 6. ◆We use a template parameter class called Record to stand for entries of the Sortable_list. ◆Record objects can be compared to each other or to a Key by first converting the Record objects to their

Every record has an associated key of type Key. a record can be implicitly converted to the corresponding Key. the keys (hence also the records can be compared under the operations > and! Any of the Record implementations discussed in Chapter 7 can be supplied by a client, as the template parameter of a sortable list An ordered list is an abstract data type defined as a list in which each entry has a key, and such that the keys are in order; that is, if entry i comes before entry jin the list, then the key of entry i is less than or equal to the key of entry j

◆Any of the Record implementations discussed in Chapter 7 can be supplied, by a client, as the template parameter of a Sortable_list. ◆An ordered list is an abstract data type, defined as a list in which each entry has a key, and such that the keys are in order; that is, if entry i comes before entry j in the list, then the key of entry i is less than or equal to the key of entry j . Every Record has an associated key of type Key. A Record can be implicitly converted to the corresponding Key. The keys (hence also the records) can be compared under the operations ' ,' ' >= ,' ' <= ,' ' == ,' and ' !=

For ordered lists, we shall often use two new operations that have no counterparts for other lists since they use keys rather than positions to locate the entry. o One operation retrieves an entry with a specified key from the ordered list. Retrieval by key from an ordered list is exactly the same as searching. oThe second operation ordered insertion, inserts a new entry into an ordered list by using the key in the new entry to determine where in the list to insert it

•One operation retrieves an entry with a specified key from the ordered list. Retrieval by key from an ordered list is exactly the same as searching. •The second operation, ordered insertion, inserts a new entry into an ordered list by using the key in the new entry to determine where in the list to insert it. ◆For ordered lists, we shall often use two new operations that have no counterparts for other lists, since they use keys rather than positions to locate the entry

Note that ordered insertion is not uniquely specified if the list already contains an entry with the same key as the new entry since the new entry could go into more than one position cat cat cat cat COW COW COW COW do dog dog dog pIg pIg hen hen ram pIg pig Ordered ram ram ram entry Move Move Complete last entry previous insertion entry

◆Note that ordered insertion is not uniquely specified if the list already contains an entry with the same key as the new entry, since the new entry could go into more than one position

8.2 Insertion Sort Example: Init ial Insert Insen Insert Insert order second t hird fourth Fifth sixth entry entry entry entry entry sorted hen cat cat cat sorted unsorted co hen cow cow cat hen hen dog ram ram ram ram hen ewe ewe ewe ewe ewe ram he sorted dog dog dog do ram Main step, contiguous case: Before rtel Unrted s current s current Remoe current sIlt entries nu lt Sorted Sorted Vertex current Reinert current Sorted Reourtel

8.2 Insertion Sort

点击下载完整版文档(PPT)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共50页,可试读17页,点击继续阅读 ↓↓
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有