Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

write pseudo code of java
Sometimes, brute force is the best we can do. Consider the following prob- lem: 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 thrower's, you save the egg. If, however, the balcony you chose is above the thrower's, the egg falls, breaks, and you lose the game. If the floor you chose is the same as the thrower's, 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. Sometimes, brute force is the best we can do. Consider the following prob- lem: 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 thrower's, you save the egg. If, however, the balcony you chose is above the thrower's, the egg falls, breaks, and you lose the game. If the floor you chose is the same as the thrower's, 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

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 Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions