Prove that the algorithm takes (o(n) running time to compute this task. Please formulate the summation equation for this proof and explain but please use summation equation.

icon
Related questions
Question

Prove that the algorithm takes (o(n) running time to compute this task. Please formulate the
summation equation for this proof and explain but please use summation equation. I am a bit confused.

public class Main {
public static void main(String[] args) {
int[] arr = {1, -1, 3, 2, -7, -5, 11, 6};
arr = moveNegative (arr);
for (int i : arr) {
}
}
}
"I
System.out.print(i + ");
1 usage
public static int[] moveNegative(int[] arr) {
int[] positive = new int[arr.length];
int[] negative = new int[arr.length];
int positiveIndex = 0;
int negative Index 0;
for (int i
}
0; i < arr.length; i++) {
if (arr[i] < 0) {
}
}
=
negative [negativeIndex++] = arr[i];
} else {
positive [positiveIndex++] = arr[i];
}
for (int i = 0; i < negativeIndex; i++) {
arr[i] = negative [i];
for (int i = 0; i < positiveIndex; i++) {
arr[negative Index + i] positive [i];
}
return arr;
Transcribed Image Text:public class Main { public static void main(String[] args) { int[] arr = {1, -1, 3, 2, -7, -5, 11, 6}; arr = moveNegative (arr); for (int i : arr) { } } } "I System.out.print(i + "); 1 usage public static int[] moveNegative(int[] arr) { int[] positive = new int[arr.length]; int[] negative = new int[arr.length]; int positiveIndex = 0; int negative Index 0; for (int i } 0; i < arr.length; i++) { if (arr[i] < 0) { } } = negative [negativeIndex++] = arr[i]; } else { positive [positiveIndex++] = arr[i]; } for (int i = 0; i < negativeIndex; i++) { arr[i] = negative [i]; for (int i = 0; i < positiveIndex; i++) { arr[negative Index + i] positive [i]; } return arr;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer