Question: Q1- 65 pts) Consider the code given to you to determine whether an expression of parentheses is balanced or not using a Doubly Linked List
Q1- 65 pts) Consider the code given to you to determine whether an expression of parentheses is balanced or not using a Doubly Linked List implementation of a Stack. Modify the code (given in the main function) to determine the maximum depth of nested parentheses in a given expression, provided the expression is balanced. Note that your code should be also able to check whether a given expression of parentheses is balanced or not. If an expression is not balanced, you should not print the value for the maximum depth of nested parentheses: your program should just print the message that the expression is not balanced and terminate. For simplicity, you can assume that the only parenthesis symbols of use areand). The maximum depth of nested parentheses in a balanced expression is the largest number of open parentheses in the stack at any time. For example, the maximum depth of nested parentheses in the expression t iS Contents of the Stack after reading the corresponding symbol in the expression Max 4 EmptyEmpty Reading the1) Expression from Left to Right Run your modified code with the following expressions and determine the maximum depth of nested parentheses of each, if the expression is balanced. Include screenshot displaying the result a. b. 1 c. ft) d. c. OI You need to submit the following for this question: (1) Briefly describe your algorithm (along with a pseudo code) to determine the maximum depth of nested parentheses in a given expression. Analyze the time complexity of the algorithm. (2) The complete code (including the modification/implementation of the algorithm in the main function) (3) Screenshots of the execution of the algorithm/code for each of the above five inputs (a)-(e)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
