Uploaded by Selim Ellieh

Lab Assignment 2

advertisement
Lebanese American University
Computer Science and Mathematics Department
CSC/BIF 310B Algorithms and Data Structures Lab
Assignment 2
Fall 2023
Deadline Nov. 24, 2023
Exercise 1 (10 points):
Suppose you have E eggs, and you live in a building with N floors. You want to know the minimum number
of attempts it takes to find out from which floor dropping the eggs will break them. The following are
certain assumptions that you can make about this problem:






An egg that survives from a fall can be reused on higher floors. For example, if you throw the first
egg on floor 1 and it survives, you can try throwing it from floor 2.
If an egg breaks, you cannot reuse it. For example, if an egg broke on floor 4, you cannot reuse it
to examine floors 1,2,3,5, and 6.
The effect of a fall is the same for all eggs. For example, if the first egg breaks from floor 4 then
the second egg will also break from floor 4.
If an egg breaks from a certain floor, then it will break from higher floors.
If an egg survives from a certain floor, then it will survive dropping it from lower floors.
There is no certainty that an egg will survive or break from the drop from any floor.
You should return the minimum number of attempts required to know from which floor the eggs will break
if you have 6 floors in your building. Assume you have 2 eggs at hand.
Exercise 2 (10 points):
Given a string, you need to find the minimum number of times you should split the string to make all the
resulting partitions into palindromes. For example, if string s is equal to mabast, then you should have 3
splits resulting in 4 partitions that are: m, aba, s, and t.
You should return the minimum number of splits needed as well as the partitions themselves.
Download