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...
Implement a function that returns the maximum number in a given unsorted linked list. For example,...
Implement a function that returns the maximum number in a given unsorted linked list. For example, there is a linked list 3->5->1->10->9. The printMax() function in max.c should return the maximum number in the linked list, namely 10 in the example. 1. Implement max.c with the completed printMax() function. 2. Provide an explanation for your solution #include <stdio.h> typedef struct node { int value; struct node *next; } node; int printMax(node *first) { // Your implementation return 0; } int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT