Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please show full and clear explanation and show all parts for good feedback thanks Algorithm problem en the question says, Give an algorithm for finding

image text in transcribed

image text in transcribed

Please show full and clear explanation and show all parts for good feedback thanks Algorithm problem en the question says, "Give an algorithm for finding such a pair." It means finding two pizzas in the stack whose diameters differ by at most (40-1 cm. 1. (Finding similar pizzas) You are given a stack of n pizza boxes of the same size, each containing 1 pizza. The pizzas in the boxes are sorted by increasing diameter; the diameters are all at most 40cm. Give an algorithm for finding such a pair. The only way your algorithm may learn the diameter of a pizza is by opening its box and measuring it. We'll call that operation measure (i), where i is the number of the box being opened. Your algorithm should open as few pizza boxes as possible. For full credit, it should open O(logn) boxes in the worst case. Hint: Remember that the boxes are sorted by pizza size. Think binary search. If you look at the middle pizza box, what can you conclude? You might need to handle odd and even boxes separately. In your solution, as with all algorithmic problem this semester, you must Briefly describe how your algorithm works in English. Give pseudocode for your algorithm. Prove that your algorithm is correct. Analyze the worst-case complexity of your algorithm as measured by the number of opened boxes

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 Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions