a. By using Big Oh notation, determine the efficiency of the best case to find a particular item for the above list. b. Define the suitable search method for the list. c. Write the algorithm based on the defined method.
d. Show the steps to determine total key comparison for searching an item 68.
QUESTION 1 Consider the list below and answer the following question: 32 45 46 57 69 68 85
a. By using Big Oh notation, determine the efficiency of the best case to find a particular item for the above list. O(1) - Locate desired item first in the array. b. Define the suitable search method for the list. Sequential search unsorted item
QUESTION 1 Consider the list below and answer the following question: 32 45 46 57 69 68 85
c. Write the algorithm based on the defined method. Begin by looking at first entry in an array. If that entry is the desired one, end the search. Otherwise search rest of the array.
public boolean contains(Object anEntry) { boolean found = false; for (int index = 0; !found && (index < length); index++) { if (anEntry.equals(entry[index])) found = true; } // end for return found; } // end contains
QUESTION 1 Consider the list below and answer the following question: 32 45 46 57 68 70 85
d. Show the steps to determine total key comparison for searching an item 68. 32 != 68 45 != 68 46 != 68 57 != 68 68 == 68 Total key comparison = 5
QUESTION 2
Based on the above list, a) How many key comparisons would have to be made to find the number 24? b) On average, how many comparisons would have to be made to find an element in the list? c) Why cant binary search be used on the list as it appears above? d) What is the Big Oh notation for the worst case?
QUESTION 2
Based on the above list, a) How many key comparisons would have to be made to find the number 24? 16 != 24 30 != 24 24 == 24 Total key comparison = 3
QUESTION 2
b) On average, how many comparisons would have to be made to find an element in the list? O(n) c) Why cant binary search be used on the list as it appears above? unsorted Item d) What is the Big Oh notation for the worst case? O(n)
QUESTION 3
QUESTION 3