## merge sorting, Data Structure & Algorithms

Assignment Help:
ESO207: Programming Assignment 1
Due on 6 Sept, 2015. To be submitted online.
Problem In this assignment you are required to implement k-way Merge Sort algorithm. In this version partition the input sequence of integers into k almost equal (may di?er by at most 1) subsequences, recursively sort, and then merge the k sequences. Input: A positive integer n, a sequence of integers (a1,a2,...,an), and a positive integer k = 2. Goal: Design a program KWMS(A,i,j,k) which sorts in decreasing order the integers contained in an array A in the index range i : j (including i and j) using k-way merge. After the completion of sorting the program should print A[i : j] starting from the new line: The sorted list in the range i:j is ........ Details: Please implement the program by strictly following these step. 1. Use three global arrays A,B,C. A contains the input sequence. B is used to form a MaxHeap, and C is used for temporary storage. 2. Let a = d(j -i + 1)/ke,b = b(j -i + 1)/kc,r = (j -i + 1)%k (remainder of (j -i + 1)÷k). Partition the array A[i : j] into A[i : i+a-1],A[i+a : i+2a-1],...,A[i+(r-1)a : i+ra-1],A[i+ra : i + ra + b],A[i + ra + b : i + ra + 2b],.... 3. In order to perform k-way merge implement a MaxHeap on another array B. Let B be a 2D array with the range [0 : 1][1 : k]. To store integer x of subarray j by setting B[a] = x and B[a] = j. 4. To perform merge operation, ?rst enter the greatest element of each non-empty sub-array into the heap, starting from the leftmost subarray (lower indices to the higher indices). Then each time the greatest element is extracted from the Heap, identify its subarray from B[] and insert the next element from that subarray into the heap. If that sub-array becomes empty, then no insertion will occur. MaxHeap
1
must be implemented exactly the way we discussed in the class. Use HeapSize to keep track of the number of elements currently in the heap. 5. The merge must be done into array C and then its content must be transferred back to A. 6. Take the array A and C lengths to be 1000 each. 7. To help us evaluate the correctness of the program, please print from a fresh line Content of the heap is B,B,...,B[k] after each extraction+insertion (or after extraction, if no insertion happens) in the heap. At the end of the routine KWMS(A,i,j,k) put a print statement which prints from a fresh line The sorted list in the range i : j is A[i],A[i + 1],...,A[j]. Note that this being a recursive program this statement will get printed after each recursive call.
2

#### Algorithm, Algorithm to find sum of square of a number

Algorithm to find sum of square of a number

#### Insertion of element into a linked list, ALGORITHM (Insertion of element in...

ALGORITHM (Insertion of element into a linked list) Step 1 Begin the program Step 2 if the list is empty or any new element comes before the start (head) element, then add t

#### Example of back face detection method, Example of Back Face Detection Metho...

Example of Back Face Detection Method To illustrate the method, we shall start with the tetrahedron (pyramid) PQRS of     Figure with vertices P (1, 1, 2), Q (3, 2, 3), R (1,

#### Time complexity, how to learn about time complexity of a particular algorit...

how to learn about time complexity of a particular algorithm

#### Algorithm for sorting a deck of cards, What is wrong with the following alg...

What is wrong with the following algorithm for sorting a deck of cards (considering the basic properties of algorithms)? I. Put the cards together into a pile II. For each ca

#### Simplifying assumptions of wire frame representation, Simplifying Assumptio...

Simplifying Assumptions of wire frame representation Neglect colour - consider Intensity: For now we shall forget about colour and restrict our discussion just to the intensi

#### How to construct binary tree, Q. A Binary tree comprises 9 nodes. The preor...

Q. A Binary tree comprises 9 nodes. The preorder and inorder traversals of the tree yield the given sequence of nodes: Inorder :          E     A    C    K    F     H    D

#### Data structure- tree, Tree is dynamic data structures. Trees can expand & c...

Tree is dynamic data structures. Trees can expand & contract as the program executes and are implemented via pointers. A tree deallocates memory whereas an element is deleted.

#### C, padovan string  