Question: The class Balanced below presents the first algorithm algol, a simple version to validate expressions. We see that a well formed expression is one that

The class Balanced below presents the first algorithm algol, a simple version to validate expressions. We see that a well formed expression is one that for each type of parenthesis (round, squared and curly brackets), the number of opening parenthesis is equal to the number of closing parenthesis.

Compile this program and experiment. First make sure that the program runs properly for valid expression such as ()[](), ([][()]). You will remark that the algorithm works for expressions that contains operands and operators: (4 * (7 - 2)).

Next you will need to find expressions where the algorithm returns true even if the expressions are not valid.

Balanced.java

public class Balanced { public static boolean algo1( String s ) { int curly = 0; int square = 0; int round = 0; for ( int i=0; i " + algo1( args[ i ] ) ); } } } 

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!