Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. (25 points) Consider a sequence of n integers such that the difference between the consecutive terms is some constant d. Suppose that you


2. (25 points) Consider a sequence of n integers such that the difference between the consecutive terms is some constant d. Suppose that you are given only n-1 of these numbers and one of them is missing. Design an algorithm that finds the missing term in O(logn) time. You may assume that the first and last integers of the original sequence are still there to avoid ambiguity. Hint: When you see O(log n) time you should first try binary-search style algorithms, which are a special kind of divide and conquer algorithms. 3. (25 points) In this question, we consider the expected running time of the QuickSort algorithm when the pivot is chosen randomly. (If you do not know what QuickSort is, part of your job is to look it up from the internet and self-learn the algorithm.) (a) (20 points) Show that it runs in O(n) time on average for some constant e < 2. Hint: Try to mimic our analysis for the randomized selection algorithm in the slides. You need to choose the range of "reasonably" good pivot wisely here. (b) (5 points) Show that it runs in O(nlogn) time on average. 4. (25 points) Let there be an array A[1,2,...,n] of numbers and we wish to find the longest increasing consecutive sub sequence. Specifically we wish to find indices i, j such that ij and A[i]

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

Probability And Statistics

Authors: Morris H. DeGroot, Mark J. Schervish

4th Edition

9579701075, 321500466, 978-0176861117, 176861114, 978-0134995472, 978-0321500465

More Books

Students also viewed these Programming questions

Question

Name each acid. a. HF(aq) b. HNO3(aq) c. H2C2O4(aq)

Answered: 1 week ago

Question

Prove that, for all positive integers n and k (n k), n+1

Answered: 1 week ago

Question

=+2. On what does McAdams say our identities depend?

Answered: 1 week ago