External ordering-11th chapter-"Data structure problem set" exercises-Min 聯繫 version

Source: Internet
Author: User

Problem sets parsing section

11th Chapter External Sorting

--"Data structure problem set"-Min. Version 聯繫

Source Code use instructions link??? data Structure-C language edition (Min, 聯繫 version) textbook source + problem sets analysis using instructions

Textbook source Collection link??? "Data structure" textbook source code compilation

Problem sets full parse link ? ? ? analysis of the problem of the data structure problems in the compilation

relevant test data download link? Data Package

The storage directory of this exercise document: Data structure \ Matching exercise analysis \ One external sort

Source code in the document directory: Data structure \ Matching exercises analysis \ One external sort \ Exercise Test document -11

Source test Data storage directory: Data structure \ Matching exercises analysis \ One external sort \ Exercise Test document -11\data

first, the basic knowledge problem

11.1. Assuming that a file is sorted internally to get 100 initial merge segments, ask:

(1) If you want to make the multi-merge three trip complete the sort, how many ways should be taken to merge at least?

(2) If the operating system requires a program to be available at the same time, the total number of input and output files is not more than 13, then the multi-merge at least a few times to complete the sorting? What if we limit the number of trips? What is the minimum number of desirable?


11.2. Assuming that the physical block size of the I/O is 150, and that 750 records can be sorted internally at a time, how many I/O are required for a 4-way balanced merge of disk files containing 150,000 records?


11.3? " What does the loser in the loser tree mean? If you use the loser tree to find the maximum number of K, in a comparison to get a>b, then who is the loser? What is the difference between "loser Tree" and "heap"?


11.4. Manually execute the algorithm K-merge to track the change process of the loser tree. Suppose the initial merge segment is:

(10, 15, 16, 20, 31, 39, +∞);

(9, 18, 20, 25, 36, 48, +∞);

(20, 22, 40, 50, 67, 79, +∞);

(6, 15, 25, 34, 42, 46, +∞);

(12, 37, 48, 55, +∞);

(84, 95, +∞)


11.5. Why permutation-select sort can get an initial merge segment with an average length of 2w? Can you establish a similar sorting method based on the substitution-insertion or substitution-exchange strategy?


11.6. The memory has a size of 6 records of the area for internal sorting, the file's keyword sequence is (51, 49, 39, 46, 38, 29, 14, 61, 15, 30, 1, 48, 52, 3, 63, 27, 4, 13, 89, 24, 46, 58, 33, 76). Try to list:

(1) The initial merging segment is obtained by the internal sorting method in the 10th chapter;

(2) The initial merging segments obtained by permutation-selection, and the change process of fi,w and FO are written;

(3) Manually perform the algorithm repl-selection with the data given above.


11.7. What is the maximum length of the initial merge segment in which the input files are sorted by permutation-selection? What is the longest length?


11.8. In which state does the input file have the shortest initial merge segment length by permutation-select sort? What is the shortest length?


11.9. What will happen to a file if it is replaced again by an output file sorted by permutation-select sort?


11.10. What is the average length of the initial merge segment given by natural selection, as described by the 11.13 questions, when the input file is in reverse order?


11.11. It is known that a file has been replaced-after selecting the sort, we get 18 initial merge segments with lengths of 47, 9, 39, 4, 12, 23, 7 and eight respectively. The 3-way balanced merging scheme is designed to external memory the least number of reads and writes, and the number of read-write external memory is obtained.


11.12. It is known that there are 31 initial merge segments of varying lengths, of which 8 segment length is 2, 8 segment length is 3, 7 segment length is 5, 5 segment length is 12, and 3 segment length is 20 (units are physical blocks). Please design a 5-way best merge scheme for this and calculate the total number of read/write external memory required.


Reprint Annotated Source: original link

second, the algorithm design problem

11.13. Suppose that when you do a permutation-select sort, you can create another secondary store (called the repository) with the same capacity as the workspace. When the entered record keyword is less than the minimax record of the just output, do not store it in the workspace, but temporarily exist in the repository, and then enter the next record, and so on, until the repository is full, and so on, and only select the record output from the workspace until the workspace is empty, so you get an initial merge segment. After that, the records in the repository are transferred to the workspace, and the sorting is started again. This method is called sort by natural selection. In general, you can find a merge segment that is longer than the permutation-select sort.

(1) Try to sort the natural selection of the file examples in section 11.4 to find the initial merging segment.

(2) The algorithm of sorting natural selection is programmed.

External ordering-11th chapter-"Data structure problem set" exercises-Min 聯繫 version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.