Computer Science, asked by shweta9531, 1 year ago

write an algorithm to mergr 2 arrays and get the result sorted in ascending order.and the sorted array must not contain duplicates​

Answers

Answered by gowrishankerganthala
0

Answer:

please mark me as brainliest answer

Answered by iadarsh
1

Answer:

Explanation:

Algorithm for Merge:

START

We have to sort both the arrays.

If we haven't yet reached the base case, we again divide both these subarrays and try to sort them.

We have to make an array of the size equal to the sum of the size of the two given array.

Now, we have to initialize two pointers i and j with 0 ( i = 0, j = 0 )

i will iterate on 1st array and j will iterate on 2nd array

Compare array[i] with array[j] if both are equal

Then store the value of array[i] in the final array and increase the value of i and j by 1.

Else if array[i] is smaller then the array[j]

Then store array[i] in the final array and increase the value of i by 1.

Else

Store array[j] in the final array and increase the value of j by 1.

END

Similar questions