Question

In: Computer Science

assume n = 2^100. consider the following problem. given an unsorted list of size n you...

assume n = 2^100. consider the following problem. given an unsorted list of size n you can choose to sort it or not first. after this step, you get m queries q1, q2, ... qm. one by one of the form "is qi in the list?" Describe whether you would sort and what algorithm you would use if 1.) m= 10, and 2) m = 1000

Solutions

Expert Solution

1) Consider the case when the list is not sorted. Then each query will take n comparisons time to answer. Hence the time taken will be proportional to
.
If the list is sorted, then sorting alone will take time at least which is already more than the time taken to answer the queries without sorting.

Hence it is better not to sort the list for answering the queries.

2) Now, when the list is not sorted, the time taken will be proportional to .

If the list is sorted, say using Merge sort, then it will take time proportional to . After this, each query will take comparisons to answer, hence the total time taken by the queries is proportional to . The total time taken in this process is . This is clearly less than when the list was not sorted.

Therefore the list should be sorted, using mergesort.

Comment in case of any doubts.


Related Solutions

Array with Pointers Find Continuous Sub-Array C++ Problem: Given an unsorted array A of size N...
Array with Pointers Find Continuous Sub-Array C++ Problem: Given an unsorted array A of size N of non-negative integers, find a continuous sub-array which adds to the given number. Declare dynamic arrays and use only pointers syntax (no [ ]’s or (ptr+i) stuff.     Input will be the number of input values to enter followed by the sum to compare with. Print out the continuous sub-array of values that are equal to sum or the message ‘No sum found’. There...
Given an unsorted integer array A of size n, develop an pseudocode with time complexity as...
Given an unsorted integer array A of size n, develop an pseudocode with time complexity as low as possible to find two indexes i and j such that A[i] + A[j] = 100. Indexes i and j may or may not be the same value.
Problem 1: Unsorted arrays Given an array of integers that is unsorted, implement the following functions:...
Problem 1: Unsorted arrays Given an array of integers that is unsorted, implement the following functions: • myAdd ( ): add an integer d to the array; return 0 if the operation is successful; return a negative number otherwise. • search ( ): given an integer d, if d is found in the array, return the index of the cell containing d. Return a negative number otherwise (e.g., d is not found in the array). • myRemove ( ): Step...
Given an unsorted array A of size N of integers, find a continuous sub-array which adds...
Given an unsorted array A of size N of integers, find a continuous sub-array which adds to the given number. Declare dynamic arrays and use only pointers syntax. (no [ ]'s or (ptr+1) stuff. input will be the number of input values to enter followed by the sum to compare with. print out the continuous sub-array of values that are equal to sum or the message 'no sum ofund.' there may be more than one sub-array to be found in...
Assume a population of 1,2 and 12. assume the sample size of size n = 2...
Assume a population of 1,2 and 12. assume the sample size of size n = 2 are randomly selected with replacement from the population. listed below are the nine different sample. complete parts a through d below 1,1 1,2 1,12, 2,1 2,2 2,12 12,1 12,2 12,12 a) find the value of the population standard deviation b) find the standard deviation of each of the nine samples the summarize the sampling distribution of the standard deviation in the format of a...
Create an unsorted LIST class. Each list should be able to store 100 names.
Create an unsorted LIST class. Each list should be able to store 100 names.
In Python please! Given an unsorted list (ls) of values (you do not know the datatype)....
In Python please! Given an unsorted list (ls) of values (you do not know the datatype). Only two values appear in the list but they appear many times and are not sorted. Without using any significant additional space (i.e. you cannot copy the list) sort the elements in linear time going through the list only once. For example: Given the list [‘a’, ‘a’, ‘b’, ‘a’, ‘a’, ‘b’, ‘b’, ‘a’] after the function, the list is [‘a’, ‘a’, ‘a’, ‘a’, ‘a’,...
A random sample of size n = 100 is taken from a population of size N...
A random sample of size n = 100 is taken from a population of size N = 600 with a population proportion of p =0.46. Is it necessary to apply the finite population correction factor? Calculate the expected value and standard error of the sample proportion. What is the probability that the sample mean is less than .40?
Implement a Priority Queue (PQ) using an UNSORTED LIST. Use an array size of 10 elements....
Implement a Priority Queue (PQ) using an UNSORTED LIST. Use an array size of 10 elements. Use a circular array: Next index after last index is 0. Add the new node to next available index in the array. When you add an element, add 1 to index (hit max index, go to index 0). Test if array in full before you add. When you remove an element, from the list, move the following elements to the left to fill in...
7. Assume a population of 46​, 51​, 53​, and 59. Assume that samples of size n=2...
7. Assume a population of 46​, 51​, 53​, and 59. Assume that samples of size n=2 are randomly selected with replacement from the population. Listed below are the sixteen different samples. Complete parts ​(a​) through (c​). Sample x1        x2 1          46        46 2          46        51 3          46        53 4          46        59 5          51        46 6          51        51 7          51        53 8          51        59 9          53        46 10        53        51 11        53        53 12        53        59 13        59        46 14        59       ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT