There is a 100-story building and you are given two eggs.
The eggs (and the building) have an interesting property
that if you throw the egg from a floor number less than X,
it will not break. And it will always brake if the floor
number is equal or greater than X. Assuming that you can
reuse the eggs which didn't broke; you got to find X in a
minimal number of throws. Give an algorithm to find X in
minimal number of throws.

Answer Posted / basvaraj s pinna

We should start from the second floor to identify the X
floor.

Step 1. Throw the one egg from second floor,
if it breaks in second floor then go to first floor,
through remaining one from the first floor
if it breaks on the first floor then X=1
else
X=2

If does not break in second floor, goto fourth floor and
throw the egg
if it breaks in fourth floor then go to third floor,
through the remaining egg from the third floor
if it breaks on the third floor then X=3
else
X=4

Similarly we should run floor = floor + 2, till one egg
breaks,

floor = floor + 2
if one egg breaks at floor then
Set currentfloor = floor -1 and check for remaining egg
throw from currentfloor, if egg breaks at currentfloor,
then X= currentfloor else X=floor
Else
floor = floor + 2

do until floor =100

Is This Answer Correct ?    10 Yes 55 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Differentiate between functions getch() and getche().

627


What are the application of void data type in c?

723


What are the types of assignment statements?

633


What are the types of variables in c?

582


Do you know what are the properties of union in c?

588






Explain how can I make sure that my program is the only one accessing a file?

633


Explain how many levels deep can include files be nested?

630


How can type-insensitive macros be created?

705


Explain about the functions strcat() and strcmp()?

601


Why is python slower than c?

609


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

657


7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.

2226


What is the benefit of using const for declaring constants?

592


What are data structures in c and how to use them?

682


Where we use clrscr in c?

711