PROGRAM TO IMPLEMENT 2-WAY MERGE SORT USING POINTERS - itstudentjunction i t s t ud ent j unct i on This site w ill be shortly www.itstude ntjunction.com. Figure: 2-way.merge sort. Mergesort is the greatest method for sorting linked lists into random order. The total computing time is of the 0(n log 2 n ). The drawback of using mergesort is that it needs two arrays of the similar size and space for the merge phase. That is, to sort a list of size n, it requires space for 2n elements. EXTERNAL SORTING C/C++ Help. In addition to the initial input pass made over the data for the internal sort. The merging of the runs requires 2-213 passes over the data (one pass to merge 6 runs of length 750 records. Two-thirds of a pass to merge two runs of length 1500. And one pass to merge one run of length 3000 and one of length 1500).
Selection Sort
It is the easiest way to sort a table. The sort is being performed from the first element; a search is performed to locate the element that is smaller than the key element. When this element is found, it is interchanged with the first element in the table. A search for the second smallest key is then carried out. Then it is started from the second element onwards. The element, which has the second smallest key, is interchanged with the element located in second position of table. This process continues till the array is in ascending order.
Pass:
Initially the elements of the array are : 9 8 7 6 5 4 3 2 1 10
| 9 1 1 1 1 1 1 1 1 1 |
| 7 8 9 3 3 3 3 3 3 3 |
| 5 6 7 8 9 5 5 5 5 5 |
| 3 4 5 6 7 8 9 7 7 7 |
| 1 2 3 4 5 6 7 8 9 9 |
Bubble Sort
It is a well-known sorting method. It differs from the selection sort in that, instead of finding the smallest record and then performing an interchange, two records are interchanged immediately upon discovering that they are out of order. In this method, after the first pass, the record with the largest key will be in the nth position. On each successive pass, the records with the next largest key will be placed in position n-1, n-2,…respectively.
Initially the elements of the array are : 9 8 7 6 5 4 3 10 2 1
| 9 8 7 6 5 4 3 3 2 1 |
| 7 6 5 4 3 5 2 1 3 3 |
| 5 4 3 7 2 1 5 5 5 5 |
| 3 9 2 1 7 7 7 7 7 7 |
| 2 1 9 9 9 9 9 8 9 9 |
Simple Merge Sort
The merge sort is a sort where the operation of sorting is closely related to the process of merging. Let assume that there are two arrays that can be combined to produce a single sorted array. This process can be accomplished easily by successively selecting the record with the smallest key occurring in either of the tables and placing this record in a new table, thereby creating an ordered list.
Merge Sort Using C
Pass:
Initially the elements of the array are :
Table 1:11 23 42
Table 2:25
New Table: 9
![]()
Table 1:23 42
Table 2:25
New Table: 9 11 23
Table 1:42
Table 2:
New Table: 9 11 23 25 42
Two Way Merge Sort
The process to merge k sorted tables into a single sorted table is called multiple merging or k-way merging. Multiple merging can also be accomplished by performing a simple merge repeatedly.
Pass:
Initially the elements of the array are : 9 83 43 64 15 28 74 8
2 Way Merge Sort Program In California
---------------------------------------------->
[9 83 43 64] [15 28 74 8]
[9] [83] [43 64] [15 28 74 8]
(9 83) (43 64) [15 28 74 8]
(9 43 64 83) [15 28] [74 8]
![]()
(9 43 64 83) (15 28) [74 8]
(9 43 64 83) (15 28) (8 74)
Merge Sort Program In Java
(8 9 15 28 43 64 74 83)
---------------------------------------------->
Quick Sort (Partition Exchange Sort)
This sorting technique performs very well on larger tables. At each step in the method, the goal is to place a particular record in its final position within a table. This technique essentially partitions the table into two subtables. The same process can then be applied to each of these subtables and repeated until all records are placed in their final positions.
Pass:
Initially the elements of the array are : 42 23 74 11 65 58 94 36 99 87
---------------------------------------------->
42 23 74 11 65 58 94 36 99 87
42 23 74 11 65 58 94 36 99 87
42 23 74 11 65 58 94 36 99 87
42 23 36 11 65 58 94 74 99 87
42 23 36 11 65 58 94 74 99 87
42 23 36 11 65 58 94 74 99 87
Insertion Sort
This sorting technique is very easy. In this, we sort the array taking into consideration the concept of insertion. If the first element is greater than the second, then we interchange them. Then we check the third element if it is smaller than the above elements then it is inserted at appropriate place.
Pass:
Initially the elements of the array are : 9 8 7 6 5 4 3 10 2 1
|9876543211 |
|7798765433 |
|5555987655 |
Two Way External Merge Sort
|3333339877 |
|101010101010101099 |
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2020
Categories |