Question

In: Computer Science

Suppose that we performed the algorithm SELECT whose running time is O(n) on 133 elements, and...

Suppose that we performed the algorithm SELECT whose running time is O(n) on 133 elements, and found the median of medians x by making groups of 5 elements. What is the maximum number of elements which are guaranteed to be greater than equals to x (without counting x, itself)?

Solutions

Expert Solution

Let the 133 elements be 1,2,3,4,.....,100,....131,132,133

Making these 133 elements as groups of 5 elements. S0 1,2,3,4,5 are one group, 6,7,8,9,10 are one group.

Likewise the groups are:

11,12,13,14,15

16,17,18,19,20

.

.

.

.

96,97,98,99,100

.

.

.

.

126,127,128,129,130 and

131,132,133

Median: The elements should be in either ascending or descending order (ordered data).

1) If the number of observations(n) is odd then the median will be at position {(n + 1) ÷ 2}

2) If the number of observations(n) is even then

i. Find the value at position {n ÷ 2}

ii. Find the value at position {(n + 1) ÷ 2}

  iii. Find the average of these two values to get the median.

The median of the group elements 1,2,3,4,5 is 3

and

The median of the group elements 6,7,8,9,10 is 8

Therefore the medians of these groups are

3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78, 83, 88, 93, 98, 103, 108, 113, 118, 123, 128, 132

There are 27(odd and ordered) medians. The median of medians will be at position {(n + 1) ÷ 2}

= {(n + 1) ÷ 2}

= {(27 + 1) ÷ 2}

= {28 ÷ 2}

= 14th position

= 68

Therefore the value of x = 68

The maximum number of elements which are guaranteed to be greater than equals to x (without counting x, itself) is 13 ( they are 73, 78, 83, 88, 93, 98, 103, 108, 113, 118, 123, 128, 132 without including x = 68)


Related Solutions

Pseudocode and algorithm of merging k sorted list with running time O(Nlogk).
Pseudocode and algorithm of merging k sorted list with running time O(Nlogk).
In class, we learned that the running time of Karatsuba’s algorithm can be expressed as the...
In class, we learned that the running time of Karatsuba’s algorithm can be expressed as the recurrence T (n) = 3T (n/2) + n. We then used the substitution method to solve the recurrence. When using the substitution method, it seems difficult to make a guess about the upper bound on the running time. However, if we use the recursion tree method, it would be a lot easier. In this question, you are asked to solve this recurrence using the...
Describe an O(n)-time algorithm that checks if brackets in a given arithmetic expression is properly placed,...
Describe an O(n)-time algorithm that checks if brackets in a given arithmetic expression is properly placed, i.e., all left brackets are matched with their right counterparts and there are no unmatched brackets between any pair of matched brackets. Note that there are generally more than one types of brackets and only those of the same type can match against each other. For simplicity, you can assume that all operands are represented as ‘a’ and addition, +, is the only available...
Give an O(lg n)-time EREW algorithm to perform the prefix computation on an array x[1. ....
Give an O(lg n)-time EREW algorithm to perform the prefix computation on an array x[1. . n]. Do not use pointers, but perform index computations directly.
Algorithm problem 4 [3.1-4] Is (2^(n+1))∈O(2^n)? Is (2^(2n))∈O(2^n)?
Algorithm problem 4 [3.1-4] Is (2^(n+1))∈O(2^n)? Is (2^(2n))∈O(2^n)?
(15 pts) Describe an O(n)-time algorithm that partitions a doubly linked list L into two doubly...
(15 pts) Describe an O(n)-time algorithm that partitions a doubly linked list L into two doubly linked lists L1 and L2, where L1 contains the odd-number-th elements in L and L2 contains the even-number-th elements in L. Elements in both L1 and L2 should appear in the same order as they appear in L. For example, if L contains the numbers 4, 7, 9, 1, and -3, in that order, then the output L1 should contain 4, 9, and -3,...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . ,...
Present an O(n) algorithm that sorts n positive integer numbers a1, a2, . . . , an which are known to be bounded by n 2 (so ai ≤ n 2 , for every i = 1, . . . , n. Use the idea of Radix Sort (discussed in class and presented in Section 8.3 in the textbook). Illustrate your algorithm by showing on paper similar to Fig. 8.3, page 198 in the textbook (make sure you indicate clearly...
Suppose we have a substring of length m and text of size n. Write an algorithm...
Suppose we have a substring of length m and text of size n. Write an algorithm to find out if the substring is present in the text or not. What is the complexity of your algorithm in terms of m and n.
Arrange elements according to electronegativity N, Ga, K, Cs, O
Arrange elements according to electronegativity N, Ga, K, Cs, O
Write an algorithm to evaluate an infix expression in Java. Calculate its running time
Write an algorithm to evaluate an infix expression in Java. Calculate its running time
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT