What is the time complexity of the following implemented algorithm?
I should notice that length of b
is enough to cover the element of a
as an index.
void smax(int[] a, int n){
int[] b = new int[n];
for (int i=0;i<b.length;i++){
b[i]=0;
}
int m=0;
while (m<b.length) {
int k=a[0];
for (int i=0;i<a.length;i++) {
if (a[i]> k && b[a[i]]!=1) {
b[a[i]]=1;
}
}
m++;
}
for (int i=0;i<a.length;i++){
if (b[a[i]]!=1){
b[a[i]]=1;
}
}
for (int j=0;j<b.length;j++){
if (b[j]==1){
System.out.println(j);
}
}
}