ComputersProgramming

Merge sort: a description of the operation of the algorithm and differences from other types of ordering of data

When developing various programs, programmers almost always have to resort to the use of sorting in order to optimize the work algorithms, improve the performance of the search operation, etc. Today, there are many different methods of arranging the elements in the required order: sorting by merge, using a key, etc. Sorting Is a set of operations, the result of which leads to the ordering of similar objects in descending or increasing order, depending on the requirements to Specific task.

All the variety of sorting algorithms can be divided into two categories: array ordering and location of files in a certain order. The first type of objects can be located not only in RAM, but also on some medium, provided that access to it is opened directly. The second category of objects should be on the material carrier: a disk or a magnetic tape.

The key difference between the ordering of array elements and the arrangement of files in the declared order is that all members of the array are accessible at any time when accessing them, and therefore the sorting process begins immediately after the start of the procedure without stopping due to the inaccessibility of one or the other Element. At the same time, when ordering files at a specific time, access can be granted only to a limited set of members.

It is often enough to sort the files using merge sort, which is developed on the fundamental principles of the arrangement of elements in a certain order. In general, the sorting procedure can be described as follows: a particular data segment is allocated and used as a key. As an example, you can consider an example of sorting mail items at the specified index. As a result, the algorithm does not perform a full analysis of the information, but at the same time it sorts the necessary elements with high probability.

The main difference between sequential files and direct access files is that they can be placed on media, which is difficult to organize permanent direct access. In addition, such files usually do not use a fixed length for stored records. Because of these features, sequential files are applied only in two situations:

- if it is necessary to use a data carrier oriented to sequential access;

- when it is convenient to use the variable length of records.

Sorting merge is often used in modern software. This is due to the widespread distribution of sequential files. For example, almost all text files are consecutive. Despite the convenience of considering a sequentially organized file as an array of data, this approach is impossible, since all elements of the file can not be accessed physically or physically.

Sorting by merge has become, in fact, the only way to sort the sequential files. Despite the fact that today there are other methods for sequencing sequential files, this method remains one of the most popular. Sorting a natural merge involves dividing the file into two parts, equal in volume to the information. Further from each file there is a gradual reading of each element from those that are available at the moment. Ordered elements are arranged in the required order in the third file, which is later divided into two similar in size. Thus, the merge sort is performed. Pascal, C, Basic - most known programming languages support the implementation of this type of sequencing of sequential files.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.