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
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...
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
This is a C++ based question that involves Data Structures and Algorithms. Q. Application: Linked List...
This is a C++ based question that involves Data Structures and Algorithms. Q. Application: Linked List of Bus Transit and Passengers You are to implement a C++ program for City Bus Transit using linked list data structure to maintain record of passengers. Specifically, you are to implement the following methods/functions: For Passenger: o A function which can create a new node of the linked list using new for each newpassenger o A function that prints the time of single passenger...
Here is a data set ( n = 117 ) that has been sorted. 14.2 21.3...
Here is a data set ( n = 117 ) that has been sorted. 14.2 21.3 22.5 22.9 23.3 23.8 23.9 24.8 25.1 26.6 26.9 26.9 27.3 27.4 27.5 27.8 28.2 28.3 28.5 28.6 28.6 29.1 29.6 29.7 29.7 29.9 30.2 30.5 30.6 30.6 30.9 31.2 31.4 31.7 31.8 31.8 32 32 32.2 32.3 32.3 32.3 32.6 32.9 33.4 33.7 33.9 33.9 34.2 34.4 34.8 34.9 34.9 35.1 35.3 35.6 35.7 36 36.4 36.7 36.8 36.9 37 37 37.1 37.1...
Individuals and organizations build various data structures and algorithms to solve real-life problems. Furthermore, many data...
Individuals and organizations build various data structures and algorithms to solve real-life problems. Furthermore, many data analysts tend to use Big-O notation for analyzing algorithms. In your own words, explain ways by which people can specify (i). data structures and (ii) algorithms, that they build and use.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT