Question: I need to find time complexity analysis (best case and worse case) on all the functions in MyArraySorted. I have attached my code for MyArraySorted

I need to find time complexity analysis (best case and worse case) on all the functions in MyArraySorted. I have attached my code for MyArraySorted below.

package apps;

public class MyArraySorted { int[] nums; int numElements=0; public MyArraySorted(){ nums = new int[100]; } public MyArraySorted(int size){ nums = new int[size]; } public MyArraySorted(int[] numbers){ nums = new int[numbers.length]; for(int i=0; i= 0) { int i = index; while (i < (numElements -1)) { nums[i] = nums[i - 1]; //shifts elements to right i++; } // for(int i=index;i nums[maxIdx]) // new challenger is greater maxIdx = i; return maxIdx; } private int binarySearch(int val) { int start = 0; int end = nums.length-1; int midpoint; while(start<=end) { midpoint = (start + end)/2; if (val > nums[midpoint]) start = midpoint + 1; else if (val < nums[midpoint]) end = midpoint - 1; else // val == nums[midpoint] return midpoint; } return -1; } public int search(int val) { return binarySearch(val); } private int linearSearch(int val){ // returns the index of the given value 'val'. // if 'val' is not found, returns -1 for(int i=0;i= i) { nums[j + 1] = nums[j]; j--; } nums[i] = number; numElements++; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!