I'd like to create a modified mergesort algorithm to return the k smallest elements of an array. The mergesort algorithm below sorts an unordered array of size n. How do I modify the algorithm so that it returns the k smallest elements of the array?A = [1...n]Mergesort (A,p,r)  //start with p = 1 and r = A.length  if p < r    q = floor((p + r)/2)    Mergesort (A,p,q)    Mergesort (A,q + 1,r)    Merge-Sort (A,p,q,r)Merge-Sort (A,p,q,r)  n1 = q - p + 1  n2 = r - q  Let L[1,2,..,n1+1] and R[1,2,..,n2+1] be new arrays  for i = 1 to n1    L[i] = A[p + i - 1]  for j = 1 to n2    R[j] = A[q + j]  L[n1 + 1] = (an infinitely big number)  R[n2 + 1] = (an infinitely big number)  i = 1  j = 1  for m = p to r    if L[i] <= R[j]      A[m] = L[i]      i = i + 1    else      A[m] = R[j]      j = j + 1
How do you return the k smallest elements of an array using Mergesort?
algorithms;search algorithms;sorting