Question: To be written in java 4. A bracket sequence consisting of '(' and ')' is defined to be valid as follows: An empty sequence is

 To be written in java 4. A bracket sequence consisting of

To be written in java

4. A bracket sequence consisting of '(' and ')' is defined to be valid as follows: An empty sequence is valid. If X is a valid bracket sequence, then (X) is a valid bracket sequence. . If X and Y are valid bracket sequences, then the concatenation of X and Y, Z=XY, is a valid bracket sequence For example, "CO)", "00", and "(00)0" are all valid bracket sequences, while "(" and "O)" are invalid bracket sequences. Given a bracket sequence, write an algorithm named "CheckBrackets.java" to judge whether it is valid or not. 5. Monkey & peaches problem. A monkey picked a pile of peaches on Monday. From that Monday to Saturday, no matter how many peaches the monkey had, each day the monkey ate of its peaches in the morning and ate one more peach in the afternoon. (For example, at the end of Wednesday, the monkey had n peaches left, then the monkey would eat +1 peaches on Thursday.) Then, on Sunday morning, the monkey found only one peach left. Do you know how many peaches the monkey picked on Monday? The answer is 190. Now, please write a recursive algorithm named "MonkeyEatPeach.java" to compute the total number of peaches that monkey picked on that Monday

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!