Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using java to write show me the output (a) Design an algorithm that takes a string, which represents an arithmetic operation, as input and checks

using java to write show me the output

image text in transcribed

(a) Design an algorithm that takes a string, which represents an arithmetic operation, as input and checks whether or not the brackets are correct (balanced) or incorrect (unbalanced). The input string may contain a combination {},L]-(),0,1,2,3,4,5,6,7,8,9,+,-,*,/. An obvious hint for this algorithm is to use the stack- based solution discussed in class as a template, and hence you can use the stack implemented in #1. Your algorithm must not check the correctness of the arithmetic operators/operands, but only check for balanced brackets. Your algorithm should also show an error message when the string contains a character that is not one of those listed above. Provide the pseudocode of the algorithm. of the following characters: (b) Implement the algorithm of (a) in your favorite programming language. Run the program in several cases, including the following (more examples to be asked when the assignment is submitted): iii. ((3*(9-(4*(6-5)))) iv. {2-{3*{6/[[[((9-0)))]]}}/7} i. (9*[3* {[(3+3)/5]*7}]) {3*(2+[3-[4/[6/9]]]}) ii. (c) Assuming an input string of size n: (i) what is the worst-case time that your algorithm takes to decide whether or not the string is correct (balanced) or incorrect (unbalanced)? (ii) Why? Give your answers in terms of the O-notation

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions