Question

3. Use the randomized select algorithm based on partition to find the median of A 14,2, 12, 6, 13, 9, 15) 4. What is the wors

please I need it urgent thanks algorithms please as soon as possible thanks in algorithms

0 0
Add a comment Improve this question Transcribed image text
Answer #1

3.

A={4, 2, 12, 6, 13, 9, 15}

Divide the list into sublists each of length five

A1={4, 2, 12, 6, 13} A2={9, 15}

Sort each list:

A1={2, 4, 6, 12, 13} A2={9, 15}

Then, get the median out of each list and put them in a list of medians, M:

M = {6, 12}

Pick the median from that list—since the length of the list is 2, and we determine the index of the median by the length of the list divided by two: we get  \frac{2}{2} = 1 , the index of the median is 1, and M[1] = 12

Use this as the pivot element and put all elements in A that are less than 76 to the left and all elements greater than 12 to the right:

A' = {4, 2, 6, 9, 12, 13, 15}

To find the third lowest score in A, find the index of 12, which is 4. How does 4 compare with 3? Since 4>3, we must recurse on the left half of the list A', which is {4, 2, 6, 9}.

9 is at index three.

So, 9 is the fourth smallest number of A.

4.

Worst Case Time Complexity - Selection algorithm in each step performs O(n) operations. But this 'n' keeps on reducing by half each time. There are totally log(N) steps. This makes it N + N/2 + N/4 + ... + 1 (log(N) times) = 2N = O(N)

Average Case Time Complexity - Average runtime is Θ(n).

Add a comment
Know the answer?
Add Answer to:
please I need it urgent thanks algorithms please as soon as possible thanks in algorithms 3....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT