Question: Problem 1:17 points A common problem for compilers and text editors is to determine if the parentheses (or other brackets) in a string are balanced

 Problem 1:17 points A common problem for compilers and text editors

Problem 1:17 points A common problem for compilers and text editors is to determine if the parentheses (or other brackets) in a string are balanced and properly nested. For example, the string "'0000" contains properly nested pairs of parentheses, but the string"00" does not; and the string "O)" does not contain properly matching parentheses. (a) 2 points] Give an algorithm that returns true if a string contains properly nested and balanced parentheses, and false if otherwise. Hint: At no time while scanning a legal string from left to right will you have encountered more right parentheses than left parentheses. (b) 13 points] Give an algorithm that returns the position in the string of the first offending d balanced. That is, if an excess right parenthesis parenthesis if the string is not properly nested an is found, return its position; if there are too many left parentheses, return the position of the first excess left parenthesis. Return -1 if the string is properly balanced and nested. (c) 2 points] Find the complexity of the two algorithms in part (a) and (b)

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!