1. Engineering
  2. Computer Science
  3. given an array of integer numbers write a linear running...

Question: given an array of integer numbers write a linear running...

Question details

Given an array of integer numbers, write a linear running time complexity program in Java to find the stability index in the given input array.

For an array A consisting n integers elements, index i is a stability index in A if

A[0] + A[1] + ... + A[i-1] = A[i+1] + A[i+2] + ... + A[n-1]; where 0 < i < n-1.

Similarly, 0 is an stability index if (A[1] + A[2] + ... + A[n-1]) = 0 and n-1 is an stability index if (A[0] + A[1] + ... + A[n-2]) = 0

Example: Consider the array A = {0, -3, 5, -4, -2, 3, 1, 0}. The stability index found at index 0, 3 and 7.

Important Notes: You must add the main method in your program in order to test your implementation. There are no data errors that need to be checked as all the data will be assumed correct. You can use the array of the previous example to test your program, however, I suggest that you also use other input arrays to validate the correctness and efficiency of your solution. Your program must be submitted only in source code form (.java file). A program that does not compile or does not run loses all points.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution