Question

In: Computer Science

Consider the "typical-case" performace for the search algorithsms. In orther words the average number of comparisons...

Consider the "typical-case" performace for the search algorithsms. In orther words the average number of comparisons needed over all possible positions where the elements can be found.

a) used to locate and element in a list of n terms with linear search

b) used to locate an element in a list of n= n^k terms using binary search.

Solutions

Expert Solution

a. used to locate and element in a list of n terms with linear search: Linear search is a simple technique which searches the array elements from the first element in the list till the last element in the list. So, in the worst case, the maximum number of comparisons will happen when you search for an element which is in the last index of the array. In that case the worst number of comparisons required in Linear Search is O(n). The same happens with the average case as well. In numbers the avearge number of comparisons required is: n/2 that also belongs to O(n).

b. used to locate an element in a list of n= n^k terms using binary search: Binary search is a technique which every time divides the array into two halves using the formulat mid = (low + high) / 2; where low is the start of the array index and high is the last array index. And the mid element is compared with the key. If the element is found, it returns true, and if the element is less than the mid element, you should search only in the left half of the array, otherwise, should search in the right half of the array. Therefore, for each comparison, the array is divided into 2 halves. Suppose if n is 2^k, then the number of elements to be compared in each pass is: 2^(k-1), 2^(k-2), .... so on. So, the required number of comparisons is k, i.e., log n. Therefore, in the worst case, the maximum number of comparisons required is: O(log n).


Related Solutions

Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of...
Analyze the worst-case, best-case, and average-case number of comparisons of sequential search if exactly three-tenths of the time, the element x to search for is not in the list and if x is in the list, it is equally likely to be in any position.
(§3.4 # 3) Use the previous problem to show that the average number of binary comparisons...
(§3.4 # 3) Use the previous problem to show that the average number of binary comparisons required to sort n items is at least O(n log2 n).
In JAVA!!! write a method called Comparisons that will return the number of comparisons to find...
In JAVA!!! write a method called Comparisons that will return the number of comparisons to find an element in the tree. The main program calls this method for each element, adding the comparisons each time in order to count the total number of comparisons. The program then outputs the total number of comparisons and the average number. You may use the program BuildTreeWIthMethod to build your tree. Then, after you have made the call to inOrder(root), add the following code:...
write a method called Comparisons that will return the number of comparisons to find an element...
write a method called Comparisons that will return the number of comparisons to find an element in the tree. The main program calls this method for each element, adding the comparisons each time in order to count the total number of comparisons. The program then outputs the total number of comparisons and the average number. You may use the program BuildTreeWIthMethod to build your tree. Then, after you have made the call to inOrder(root), add the following code: int totalComparisons=0;...
A study is run to estimate the average number of toilet paper rolls a typical U.S....
A study is run to estimate the average number of toilet paper rolls a typical U.S. household currently have. Say a sample of 10 households is selected last month and they reported the number of toilet paper (in rolls) as follows.                        75         56        50        94        65       111      97        88            103        98 Assume the average amount of toilet paper a household usually have is 55 rolls at national level. Test whether the mean number of toilet paper rolls in this sample is significantly different from the national level? Use...
What is the number of comparisons in the bubble sort algorithm, if it is used to...
What is the number of comparisons in the bubble sort algorithm, if it is used to sort a list of n-entries? Justify your formula.
The average number of words in a romance novel is 64,393 and the standard deviation is...
The average number of words in a romance novel is 64,393 and the standard deviation is 17,382. Assume the distribution is normal. Let X be the number of words in a randomly selected romance novel. Round all answers to 4 decimal places where possible. a. What is the distribution of X? X ~ N(_,_) b. Find the proportion of all novels that are between 52,226 and 62,655 words. c. The 70th percentile for novels is  words. (Round to the nearest word)...
The average number of words in a romance novel is 64,245 and the standard deviation is...
The average number of words in a romance novel is 64,245 and the standard deviation is 17,316. Assume the distribution is normal. Let X be the number of words in a randomly selected romance novel. Round all answers to 4 decimal places where possible. a. What is the distribution of X? X ~ N( , ) b. Find the proportion of all novels that are between 48,661 and 65,977 words. c. The 95th percentile for novels is words. (Round to...
The average number of words in a romance novel is 64,200 and the standard deviation is...
The average number of words in a romance novel is 64,200 and the standard deviation is 17,431. Assume the distribution is normal. Let X be the number of words in a randomly selected romance novel. Round all answers to 4 decimal places where possible. a. What is the distribution of X? X ~ N( , ) b. Find the proportion of all novels that are between 62,457 and 74,659 words. c. The 95th percentile for novels is words. (Round to...
The average number of words in a romance novel is 64,419 and the standard deviation is...
The average number of words in a romance novel is 64,419 and the standard deviation is 17,160. Assume the distribution is normal. Let X be the number of words in a randomly selected romance novel. Round all answers to 4 decimal places where possible. a. What is the distribution of X? X ~ N(,) b. Find the proportion of all novels that are between 71,283 and 83,295 words. c. The 85th percentile for novels is  words. (Round to the nearest word)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT