For this problem A is an array of length n objects that has at most k distinct keys in it, where. Our goal is to compute a sorted array B that contains the k distinct keys occurring in A. a. Design an algorithm that is computing the sorted array B of length k containing the k distinct keys. The value of k is not provided as input to the algorithm. b. Analyze your algorithm for part a.

Respuesta :

Answer:

sdsdsd

Explanation:

Given: A is an array of length n objects that has at most k distinct keys in it.

To find: sorted B array that has k distinct keys in A.

Algorithm:

Sort_array(n)

{

Iterate through n elements of your list and remove duplicate values from it. In python you

can do this operation by set function with O(n) complexity

unique_A = set (A)  

Then sort this unique array in python by sorted function with O(nlogn) complexity  

sorted_B = sorted (unique_A)

}

Ver imagen zahidahmadkhantanoli
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE