Question

In: Computer Science

(Subject: Data Structures and Algorithms) Faster merging. You are given two sorted sequences of $\lg{n}$ and...

(Subject: Data Structures and Algorithms)

Faster merging.

You are given two sorted sequences of $\lg{n}$ and $n-1$ keys. We would like to merge those two sorted sequences by performing $o(n)$ comparisons.

(Note we are interested in comparisons, not running time.) Show how this can be done or argue that it cannot be done.

Note: In class we showed that ordinary merging would require no more than $\lg{n}+n-1+1= n + \lg{n}$ comparisons.

Solutions

Expert Solution

Firstly we have given two sorted arrays of lg(n) and n-1 keys that is elements . Here as log is not specified so I am taking lg as logarithm of base 10.
So these are the elements of the given sorted arrays and number of comparisons to be done is merging two sorted arrays are defined by the number of elements of arrays to be merged.
When two sorted arrays are going to be merged the comparisons to be made either in case of worst situation and normal situation is--
Let's consider two sorted list of n and m elements then,

  • 1)In case of normal situation it is considered that one array list is small than the other and after comparing all the elements of the smaller list the remaining elements of the other list will be added directly to the new merged array list and the number of comparisons will depend on the smaller array list that is total number of comparisons will be same as number of elements in the smaller list. Let the smaller list have n elements then the number of comparisons to be done will be n that is comparisons will be min(n,m).
  • 2)Second case scenario will be when both list have same number of elements then the merged list will be obtained by comparing each list element with the other again and again till the both list are ended. That is in this case the number of comparisons made will be m+n-1.

=========================================================================

Now, lets come to the question.
Let's take n as 10 so in first sorted array number of elements will be lg(10)=1 and in case of second array it will be 9 now it is given that the sorted arrays are merged by having O(n) comparisons but the number of elements we obtained are 1 and 9 that is they are similar to the first case and thus number of comparisons made for n=10 is 1 .
If we take n=100 then the elements will be 2 and 99 still it follows the first case and the number of comparisons made will be 2. There is no situation to be thought of that can have O(n) comparisons.
Thus it cannot be done as the keys given will never generate a situation where the elements will have same elements, the elements of one list will always be smaller than the other list and it will always be smaller than n. Thus it cannot be done.


Related Solutions

You are given 2 sorted sequences of log(n) and n-1 keys. We would like to merge...
You are given 2 sorted sequences of log(n) and n-1 keys. We would like to merge those 2 sorted sequences by performing o(n) comparisons.[Note that we are interested in the comparisons and not the running time.] Show how this can be done or argue how this cannot be done. In class we show that ordinary merging would require no more than lg(n)+n-1+1 = n+lg(n) comparisons.
Write the algorithm, following the ideas given in class, for merging two sorted arrays into one...
Write the algorithm, following the ideas given in class, for merging two sorted arrays into one sorted array. Note the algorithm is not the one for merge sort. 2) What is the best asymptotic upper bound for the algorithm? List reasoning steps.
what are Sorted lists and their efficiency? in c++ and data structures
what are Sorted lists and their efficiency? in c++ and data structures
C++ Data Structures 4. Write a client function that merges two instances of the Sorted List...
C++ Data Structures 4. Write a client function that merges two instances of the Sorted List ADT using the following specification. MergeLists(SortedType list1, SortedType list2, SortedType& result) Function: Merge two sorted lists into a third sorted list. Preconditions: list1 and list2 have been initialized and are sorted by key using function ComparedTo. list1 and list2 do not have any keys in common. Postconditions: result is a sorted list that contains all of the items from list1 and list2. c. Write...
Data Structures and Algorithms CMPS 2720 PLEASE ANSWER CLEARLY 10. Suppose a dataset has N items....
Data Structures and Algorithms CMPS 2720 PLEASE ANSWER CLEARLY 10. Suppose a dataset has N items. On average, how many comparisons and how many saves (not swaps) are needed to sort the dataset using the bubble sort? 11. Suppose a dataset has N items. On average, how many comparisons and how many saves (not swaps) are needed to sort the dataset using the select sort? 12. Suppose a dataset has N items. On average, how many comparisons and how many...
Divide and conquer problem. Suppose we are given two sorted arrays A[1 . . . n]...
Divide and conquer problem. Suppose we are given two sorted arrays A[1 . . . n] and B[1 . . . n] and an integer k. Describe an algorithm to find the kth smallest element in the union of A and B in O(log n) time. For example, if k = 1, your algorithm should return the smallest element of A ∪ B; if k = n, your algorithm should return the median of A ∪ B.) You can assume...
This question is in reference to BFS and DFS for data structures and algorithms Consider a...
This question is in reference to BFS and DFS for data structures and algorithms Consider a graph algorithm with a growth function on V and E: f(V, E). How would you convert f(V,E) to f'(V) such that f(V,E)=O(g(n))=f(V)? (That is, convert a growth function of two variables to be of one variable in such a way that the Big-Oh bound for the one variable function will hold for the two variable function.) Explain the steps in creating f', and explain...
Thoroughly explain the impacts of data structures and algorithms in the development and implementation of computer...
Thoroughly explain the impacts of data structures and algorithms in the development and implementation of computer programs using modern computer technologies.
What are the data structures and algorithms? Why are they important to software developers? Give an...
What are the data structures and algorithms? Why are they important to software developers? Give an example of using a data structure. Give an example of using algorithm. Use Google to search for your answers. Minimum 400 words and a maximum of 1000 words.
Data Structures and Algorithms Activity Requirement: Implement a queue using an array as its underline data...
Data Structures and Algorithms Activity Requirement: Implement a queue using an array as its underline data structure. Your queue should fully implemnted the following methods: first, push_back (enqueue), pop_front (dequeue), size, and isEmpty. Make sure to include a driver to test your newly implemented queue
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT