Question: 1- Please calculate the Best, Average and Worst time complexities of the function below. (Assume length of the array equals to n) function itemExists(array,
1- Please calculate the Best, Average and Worst time complexities of the function below. (Assume length of the array equals to n) function itemExists(array, item) ( for (int i= 0; i < array. length; i++) if (array[i]== item) return true; return false;
Step by Step Solution
There are 3 Steps involved in it
Best Case Time Complexity The best case time complexity of the function itemExists is O1 This occurs when the element to be searched for is present at the first index of the array In this case the fun... View full answer
Get step-by-step solutions from verified subject matter experts
