Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

Define Industry 4.0.

Answered: 1 week ago

Question

What is interest? How does interest affect credit card purchases?

Answered: 1 week ago

Question

Understand the roles of signs, symbols, and artifacts.

Answered: 1 week ago

Question

Know the three main dimensions of the service environment.

Answered: 1 week ago