Question

John needs a data structure for searching 10240 keys, but he knows that 80% of these...

John needs a data structure for searching 10240 keys, but he knows that 80% of these searches for keys that are actually present involve only 20% of the keys. He decides to separate these 2048 keys into one ordered table, and keep the other 8192 keys in a separate but also ordered table. To find a key he will look in the small table first, using binary search, and if the key is not found we look in the large table using the same algorithm.

Note: [ ] represent ceiling function notation

Problem 1: In the worst case, John's algorithm takes time ______ while binary search on a single table of size 10,240 takes time _______; pick the most accurate representation:

A. [log2(2048)] + [log2 (8192)] ; [log2 (8192)]

B. [log2(2048)] + [log2 (8192)] ; [log2 (10240)]

C. [log2(2048)] + 0.2 * [log2 (8192)] ; [log2 (8192)]

D.  [log2(2048)] + 0.2 * [log2 (8192)] ; [log2 (10240)]

E.  [log2(2048)] + 0.2 * [log2 (8192)] ; 0.8 * [log2 (10240)]

Problem 2: In the expected case for successful searches, John's algorithm takes time ________ while binary search on a single table of size 10240 takes time ______; pick the most accurate expression.

A. [log2(2048)] + [log2 (8192)] ; [log2 (8192)]

B. [log2(2048)] + [log2 (8192)] ; [log2 (10240)]

C. [log2(2048)] + 0.2 * [log2 (8192)] ; [log2 (8192)]

D.  [log2(2048)] + 0.2 * [log2 (8192)] ; [log2 (10240)]

E.  [log2(2048)] + 0.2 * [log2 (8192)] ; 0.8 * [log2 (10240)]

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

Binary Search:- In Binary Search we can search elements in sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. Go to the left half if the value of the search key is less than the item in the middle of the interval. Otherwise go for the right half. Repeatedly check until the value is found or the interval is empty.

So we have to   divide by 2 until we have only one element left that is -

n/2k=1( if array is having n elements)

that is 2k=n

k=log2n This is the worst case time complexity of the binary search Therefore for worst case as john is also using binary search on two arrays for problem 1 option B is correct.

When we think of the Best case of Binary search It occurs when the element you are searching for is the middle element of the list/array . In that case you will get the desired result in a single search.

Time Complexity of the Algorithm in such a case will be O(1).

But in problem 2 you stated expected case for successful searches that means we should think for average case. and for average case time complexity of binary search is also log2n.

Therefore according to me for problem 2 also option B is correct.

Add a comment
Know the answer?
Add Answer to:
John needs a data structure for searching 10240 keys, but he knows that 80% of these...
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
  • I NEED HELP WITH THIS HOMEWORK!!!! What is a characteristic of a bag data type? Elements...

    I NEED HELP WITH THIS HOMEWORK!!!! What is a characteristic of a bag data type? Elements are added and removed in any order Elements are removed in the same order they were added Distinct elements are added in any order but are removed beginning with the last one added Distinct elements are removed in the reverse order they were added Which scenario illustrates a data stack structure Standing in a line to be serviced Filing documents in alphabetical order Offering...

  • Programming Assignment 1 Data structure Java Implement Shellsort for a linked list, based on a variant...

    Programming Assignment 1 Data structure Java Implement Shellsort for a linked list, based on a variant of bubble sort. The rather severe constraints imposed by the singly-linked list organization presents special problems for implementing Shellsort. Your task is to overcome these constraints and develop a simple, elegant implementation that does not sacrifice efficiency or waste space. Step 1. First, implement a routine to build a list: read integers from standard input, and build a list node for each item consisting...

  • Please read the article and answer about questions. You and the Law Business and law are...

    Please read the article and answer about questions. You and the Law Business and law are inseparable. For B-Money, the two predictably merged when he was negotiat- ing a deal for his tracks. At other times, the merger is unpredictable, like when your business faces an unexpected auto accident, product recall, or government regulation change. In either type of situation, when business owners know the law, they can better protect themselves and sometimes even avoid the problems completely. This chapter...

  • I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter T...

    I need help with my very last assignment of this term PLEASE!!, and here are the instructions: After reading Chapter Two, “Keys to Successful IT Governance,” from Roger Kroft and Guy Scalzi’s book entitled, IT Governance in Hospitals and Health Systems, please refer to the following assignment instructions below. This chapter consists of interviews with executives identifying mistakes that are made when governing healthcare information technology (IT). The chapter is broken down into subheadings listing areas of importance to understand...

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