Question

In: Computer Science

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.

Solutions

Expert Solution

Worst-case complexity: O(n)

The worst case of sequential search is if either the last element was the target or if the target was not even in the list. Both cases would take nn comparisons, with n being the size of the list in question. Thus the worst case complexity is O(n).

But this assumes the target only appears on the list once/never. In general, it could appear k times. The worst configuration for the target elements to be in is if they are all at the end of the list, in which case we would need n−k+1comparisons to get to the first instance of the target. Giving us a more general worst case complexity of O(n−k)

Best-case performance: O(1)

The best case of sequential search is if the first element of the list is the target. In this case it takes only 1 comparison to return the successful search. Thus the best case complexity is O(1).

Average performance: O(n)

The average case complexity of a search algorithm is the sum of the times it takes to search for each element divided by the number of elements. More formally:

  n
s1+s2+⋯+sn    = ∑ Si

n i=1 n

Where si is the time it takes to search for the i th element, and n is the length of the list.

  

s1 + s2 +⋯+ n =    n(n+1) .   1 = n+1  

n 2 n 2

In sequential search, we have to perform i comparisons to return i th element. Because of this we can write:

n+1  

k+1

But this assumes the target only appears once on the list. In general, it could appear k times (randomly strewn about) in which case there is a more general average case:

Thus the average case complexity of sequential search is O(n / k) or O(n) if we don't vary k.


Related Solutions

IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 3 Search list for some items as follows: a. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.) b. Use the binary search algorithm to search the list, switching to a sequentialsearch when the size...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential...
IN C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 2 Use any sorting algorithm to sort list.
In C++ Write a program to find the number of comparisons using binarySearch and the sequential...
In C++ Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 5.1 Use a random number generator to fill list.
Write a program in C++ to find the number of comparisons using binarySearch and the sequential...
Write a program in C++ to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. a. Use a random number generator to fill list. b. Use any sorting algorithm to sort list. c. Search list for some items as follows: i. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.)...
Question 5 Write a program to find the number of comparisons using binarySearch and the sequential...
Question 5 Write a program to find the number of comparisons using binarySearch and the sequential search algorithm as follows: Suppose list is an array of 1000 elements. 5.1 Use a random number generator to fill list. 5.2 Use any sorting algorithm to sort list. 5.3 Search list for some items as follows: a. Use the binary search algorithm to search the list. (You may need to modify the algorithm given in this chapter to count the number of comparisons.)...
Conduct a web search on "The best and worst PowerPoint presentations" using your favorite search engine......
Conduct a web search on "The best and worst PowerPoint presentations" using your favorite search engine... which is google. give two reasons why this website was your choice of either the best or worst PowerPoint presentation and discuss what should or should not be done when creating a PowerPoint presentation. At the end of the oaragraph put the URL of the website.
20. The concept of best-, worst-, and average-case analyses extends beyond algorithms to other counting problems...
20. The concept of best-, worst-, and average-case analyses extends beyond algorithms to other counting problems in mathematics. Recall that the height of a binary tree is the number of edges in the longest path from the root to a leaf. (a) Find the best-case height of a binary tree with five nodes. (b) Find the worst-case height of a binary tree with five nodes. (c) Find the average-case height of a binary tree with five nodes. For this problem,...
What is the Average time complexity of sequential search algorithm in a linked list?
What is the Average time complexity of sequential search algorithm in a linked list?
What is the best case and worst case performance for a hashtable lookup explain answer very...
What is the best case and worst case performance for a hashtable lookup explain answer very clearly and answer must be explained how hashtables work and how that relates to performance in both the cases.
Accountants are counted on to provide management with analyzing data to determine best- and worst-case scenarios....
Accountants are counted on to provide management with analyzing data to determine best- and worst-case scenarios. As future planning becomes more complex, these what-if analyses can increase in complexity and usefulness. Identify and discuss at least three (3) types of what-if analyses that an accountant should be able to perform to measure a firm’s performance over a period. Be sure to include the type of data that will be needed to support this analysis. Justify your response.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT