Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

just need part e) (16 points) Consider the following algorithm to find the second largest number from an array S[1.n) 2. int max, max2; if

image text in transcribed

just need part e)

(16 points) Consider the following algorithm to find the second largest number from an array S[1.n) 2. int max, max2; if (max = S[1]; max2 = S[2];} else (max = S[2]; max2-S[1];} For (i = 3; i max) (max2 = max; s[i];} max = else if (s[i] max2) (max2 = s[i]); For each element in S[3..n], what is the minimum/maximum number of (> comparisons that will be executed? What is the minimum total number of (>) comparison that need to be executed? What is the maximum total number of (>) comparison that need to be executed? Now consider the randomized version of the algorithm by permuting S randomly before executing the algorithm above. Let Y be the total number of () comparison that is need for a given input S. Let Xi (3 is n) = 1 if the "else if" line is executed for s[i] and 0 otherwise. Write Y in terms of X Show that the expected number of (>) comparison in the randomized algorithm is less than n -2+ 2log2n (Hint: 1+ 1/2+ 1/3 +....+ 1 s 1 + log2n) a. b. c. d. e

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Modeling And Design

Authors: Toby J. Teorey, Sam S. Lightstone, Tom Nadeau, H.V. Jagadish

5th Edition

0123820200, 978-0123820204

More Books

Students also viewed these Databases questions

Question

=+With whom does the firm have to negotiate?

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago