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
a) Identify the following declarations. Ex. int i (integer variable) float a[l0](array of 10 real nos) int (*f())() void *f int (*f()) [] void *f int f[] [] [] char *(*f) () int (*f[]) [] float(*f) [] [] float **f int ******f
Can we replace the struct function in tree syntax with a union?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
What is wild pointer in c with example?
Can we access the array using a pointer in c language?
what are # pragma staments?
What is 1d array in c?
How to write a multi-statement macro?
What are the types of data structures in c?
What is keyword with example?
Explain how can you tell whether a program was compiled using c versus c++?
How will you print TATA alone from TATA POWER using string copy and concate commands in C?
Explain the difference between malloc() and calloc() function?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
Difference between linking and loading?