Question

In: Computer Science

How many key comparisons are made by mergesort in the a. Best case? b. Worst Case?

How many key comparisons are made by mergesort in the

a. Best case?

b. Worst Case?

Solutions

Expert Solution

Merge sort is a divide and conquer algorithm.

It divides the array into smaller pieces sorts the smaller pieces and combines them.

Now comaprisons only take place during merging not in splitting the array or on recursive calls.

Imagine 2 arrays of size a and b are merged

Best case comparison - min(a,b) because arrays will already be sorted in the order in which they can be combined .

Ex- all elements in array1 is less than that of first element in array 2 and both arrays are already sorted in ascending order . Size of array 1 <Size of array 2 then we need to need to compare each element of array 1 with first element of array 2 only. All elements of array 2 will be after array1 elements.

Worst case- a+b-1

When all alternate elements of each array goes into the sorted array.

Here -1 is there because comparison takes place between 2 elements and in last comparison one is smaller and the greater will then occupy the next position without any further comparison.


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.       How many successful and unsuccessful comparisons will by made using brute force string matching in a...
3.       How many successful and unsuccessful comparisons will by made using brute force string matching in a binary string of 1000 zeros while trying to match the following patters: a.       1000 b.       0001 c.       00010
How Many Comparisons would be made by binary when searching a list of one million elements...
How Many Comparisons would be made by binary when searching a list of one million elements in the best and worst case ?
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.
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.
I need the exact answer for: Best-case NPV: Worst-case NPV McGilla Golf has decided to sell...
I need the exact answer for: Best-case NPV: Worst-case NPV McGilla Golf has decided to sell a new line of golf clubs. The clubs will sell for $855 per set and have a variable cost of $415 per set. The company has spent $320,000 for a marketing study that determined the company will sell 70,000 sets per year for seven years. The marketing study also determined that the company will lose sales of 13,400 sets of its high-priced clubs. The...
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,...
How many character comparisons will the BMH algorithm perform to solve the pattern search problem shown...
How many character comparisons will the BMH algorithm perform to solve the pattern search problem shown below? text: my next door neighbor is a witch pattern: is explain c language
Given a list of 4096 sorted values, about how many comparisons can you expect to be...
Given a list of 4096 sorted values, about how many comparisons can you expect to be performed to look for a value that's not in the list using the bubble sort algorithm?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT