Here's my program, i'm able to get the time complexity partially can anyone help me with this:
I'am able to get some of them, but can anyone verify if my approach is right
package sd;
public class Max {
public static void main(String args[]) {
int i;
int large[] = new int[5];
int array[] = { 33, 55, 13, 46, 87, 42, 10, 34, 43, 56 };
int max = 0, index = 0;
// O(5)
for (int j = 0; j < 5; j++) {
max = array[0]; // Assuming max to be first element
// Comparing 1st element with max O(n)
for (i = 1; i < array.length; i++) {
if (max < array[i]) {
max = array[i]; // Replace if greater
index = i;
}
}
large[j] = max;
array[index] = Integer.MIN_VALUE; // Find max and replace with least
// possible value to avoid
// duplicate max
System.out.println("Largest 5 amoung 10 : " + large[j]); // Time
// complexity:
// O(5)
// *
// O(n)
// =
// O(n)
}
}
}