Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Sometimes, brute force is the best we can do. Consider the following problem: You live in a building of n floors. Someone keeps throwing eggs

Sometimes, brute force is the best we can do. Consider the following problem: You live in a building of n floors. Someone keeps throwing eggs out of a balcony on some unknown floor f. At each time slot, this person will throw an egg. At each time slot, you can go to a balcony on any floor and attempt to save the egg. If the balcony you chose is below the throwers, you save the egg. If, however, the balcony you chose is above the throwers, the egg falls, breaks, and you lose the game. If the floor you chose is the same as the throwers, you catch him and you win, saving the next generation of eggs.

1. Write a brute-force algorithm that will always win in this game without losing any eggs in the minimum number of time-slots. The input to your algorithm should be the number of floors n, and the output should be an array X of n integers, one integer for each time-slot. The entry X[i] determines which floor your algorithm will go to, at time-slot i.

2. A more efficient algorithm would catch the thrower in fewer time-slots than yours. Argue that there should not be a more efficient algorithm.

3. Prove that if any algorithm A2 faster than yours exists, there will be some instance of this problem where A2 looses

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

What Is A Database And How Do I Use It

Authors: Matt Anniss

1st Edition

1622750799, 978-1622750795

More Books

Students also viewed these Databases questions