Give an algorithm that returns the position

Assignment Help Data Structure & Algorithms
Reference no: EM13691700

Question: 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 "((())())()" contains properly nested pairs of parentheses, but the string ")()(" does not; and the string "())" does not contain properly matching parentheses.

Part (a) 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.

Part (b) Give an algorithm that returns the position in the string of the first offending parenthesis if the string is not properly nested and balanced That is, if an excess right parenthesis 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.

Can you solve this problem and show all the workings.

Reference no: EM13691700

Questions Cloud

Program that will read in 8 numbers into an array : Write a program that will read in 8 numbers into an array. Print out the numbers from the array, then print the 2nd number, the 5th number and the last number.
Write a method compact that removes all zeroes : Write a program that reads a text file (compact.txt) and stores the integers in an array.  Your instructor will provide this text file.
Write a program which initialize an integer array : Write a program which performs the tasks - return the control to main( )and print the new array elements in main.
Steps in preparing a high level language program : Describe the purpose of each step in preparing a high level language program for execution (editing, compiling, linking, and loading).  Include in your description the types of files created with each of the first three steps.?
Give an algorithm that returns the position : 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..
Define an adt for character strings : Define an ADT for character strings. Your ADT should consist of typical functions that can be performed on strings, with each function defined in terms of its input and output. Then define two different physical representations for strings.
Describe ways to generalize a simple sorting algorithm : Describe ways to generalize a simple sorting algorithm (such as insertion sort, or any other sort you are familiar with) to support this generalization
The keto form of uracil predominates at room temperature : Problem- Suggest a spectroscopic method that could be used to show that the keto form of uracil predominates at room temperature. Why does the keto form predominate over the enol form
Is it likely that both ring connections are mad : Problem- Is it likely that both ring connections are mad simultaneously in this experiment (Miniscale synthesis of a substituted pyrimidine) as was observed for the diels-alder synthesis

Reviews

Write a Review

 

Data Structure & Algorithms Questions & Answers

  Create a solution algorithm using pseudocode

Algorithm that will receive two integer items from a terminal operator, and display to the screen their sum, difference, product and quotient.

  Using command line options in bash shell script

Design a script that will permit the user to enter one of several choices from the command line. The specific requirements are as follows:

  What is the running time of your algorithm

Give an ef?cient algorithm to determine if there exists an integer i such that Ai = i in an array of integers A1

  In this assignment you are to write a program that analyzes

in this assignment you are to write a program that analyzes a selection of text counting the number of times each word

  The warehouses the firm supplies retail outlets

DSS Inc. is an electronics company with production facilities located in Atlanta, Boston, and Chicago. Components produced at these facilities may be shipped to the firm's regional warehouses that are located in Edison and Fargo. From the warehouses ..

  Create a flowchart to determine the cause of problems

Assume you are the 1st level help desk technician at a average sized corporations. Your job is to handle the initial calls from corporation  computer users with personal computer related problems.

  Discussion on data mining techniques

The tax authorities working for many governments are often confronted with challenge of detecting tax evasion and fraud. Suppose you work at income tax department.

  What are the equivalence classes of this relation

Show that the reachability matrix R for an undirected graph with n vertices can be constructed in 0 ( n 2 )time.

  Explain algorithm which gives initial infection of computer

Explain an O(m+n) algorithm which, given an initial infection of a computer Ca at time t determines for each other computer the earliest time at which it can become infected.

  Write a method that finds the average age of the students

Write a method that finds the average age of the students stored in the data structure and some Java code that could be used in a test program to display the value returned by the method on the console or command prompt.

  Write down a 3-4 page apa formatted paper describing

write 3-4 page apa formatted paper discussing whether in the next few years rdbms will be replaced completely partially

  Creating a big inteter calculator program

Create a big-inteter calculator program that permits the user to enter two large integers and the operation to be performed and that calls appropriate function to carry out the designated operation.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd