0 votes
in Other by

Create a program that prints the k largest elements of an array. An array element can have any order. If you have an array of [1, 23, 12, 9, 30, 2,50] and are asked to print the largest three elements, i.e., k = 3, the output should be 50, 30 or 23

1 Answer

0 votes
by
Solution:

Modify Bubble Sort to run an outer loop maximum of k times.

Print the last k elements from the array created in step 1.

The complexity of Time: O(n*k).
...