Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CS 344 Sections 1,2,3 Fall 2018 Homework 4. Due Tuesday, November 13, 11:55pm 80 points total plus extra credit Problem 1: Random Binary Search (20

image text in transcribed
image text in transcribed
CS 344 Sections 1,2,3 Fall 2018 Homework 4. Due Tuesday, November 13, 11:55pm 80 points total plus extra credit Problem 1: Random Binary Search (20 points total) 1 Consider the Following Problem: . Input: a sorted array A of length n, and a target numberk Owsgpet: indes isuch that Al- or no solion f e Previously, we showed that binary search solves this problem in O(log(n) time by repeatedly looking at the middle and recursing to one side. Let's say that instead of picking the middle element, we picked a random element in the array. Here is the pseudocode. Algorithm: RandomBinarySearch(A,k,left,right) in the initial call, left 0 and right n-l 1. If left > right return "no solution" 2. iRand(left....right) 3. If Ali] k return i 4. If AH >k return RandomBinarySearch(A,k,left, i-1) 5. IfAlilck . RandomBinarySearch(A,k,i+1,right) In this question, we will figure out the expected running time of this RandomBinarySearch. Note that all the work done by the algorithm consists of comparing some Alt] to k (and then recursing and comparing some other Ali to k). In particular, each Ali] is compared to k either 0 or 1 times. The expected running time is thus the expected number of comparisons made by the algorithm. CS 344 Sections 1,2,3 Fall 2018 Homework 4. Due Tuesday, November 13, 11:55pm 80 points total plus extra credit Problem 1: Random Binary Search (20 points total) 1 Consider the Following Problem: . Input: a sorted array A of length n, and a target numberk Owsgpet: indes isuch that Al- or no solion f e Previously, we showed that binary search solves this problem in O(log(n) time by repeatedly looking at the middle and recursing to one side. Let's say that instead of picking the middle element, we picked a random element in the array. Here is the pseudocode. Algorithm: RandomBinarySearch(A,k,left,right) in the initial call, left 0 and right n-l 1. If left > right return "no solution" 2. iRand(left....right) 3. If Ali] k return i 4. If AH >k return RandomBinarySearch(A,k,left, i-1) 5. IfAlilck . RandomBinarySearch(A,k,i+1,right) In this question, we will figure out the expected running time of this RandomBinarySearch. Note that all the work done by the algorithm consists of comparing some Alt] to k (and then recursing and comparing some other Ali to k). In particular, each Ali] is compared to k either 0 or 1 times. The expected running time is thus the expected number of comparisons made by the algorithm

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 Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

how can internal auditors best detect fraud in their organization

Answered: 1 week ago

Question

Discuss the states of accounting

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago