Returns true if a string contains properly nested

Assignment Help Data Structure & Algorithms
Reference no: EM13168045

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.

(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.

(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.

Reference no: EM13168045

Questions Cloud

Payroll and uses the selection construct : This problem involves payroll and uses the selection construct. A possible restatement: An hourly employee's regular payRate is $16.78/hour for hoursWorked
Compute the percent of the rdi : The student ended up calculating that he/she has 2.19 ppm of Vitamin B2 in the diluted sample. Calculate the percent of the RDI of Riboflavin satisfied by consuming this tablet
Design an ethernet network to connect a single client pc : Design an Ethernet network to connect a single client PC to a single server.  The two devices are 410 feet apart.  They need to communicate at 800 Mbps.  Your design will specify the locations of switches and the transmission line between the switche..
Explain what is the calorimeter constant : If the final temperature of the system is 59.4 oC, what is the calorimeter constant (Ccalorimeter) ? Use 4.184 J/goC for the heat capacity of water.
Returns true if a string contains properly nested : 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..
Explain how much energy is required to heat : How much energy (in Joules) is required to heat 10.99 g of water from 12.9 Celsius to 42.4 Celsius?
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.
Imagine that you have been assigned : Imagine that you have been assigned to implement a sorting program. The goal is to make this program general purpose, in that you don't want to define in advance what record or key types are used
How large a value can be stored in an integer variable : Most programming languages have a built-in integer data type. Normally this representation has a fixed size, thus placing a limit on how large a value can be stored in an integer variable

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Give a recursive algorithm for finding the number of one''s

Give a recursive algorithm for finding the number of one's in a bit string, name the algorothm count-ones.

  Creating erd with primary, foreign keys and main attributes

A very small college wishes to keep track of history of all administrative appointments, The college chancellor may wish to know how many deans worked in college of business between January 1, 1960 and January 1 2008

  Computing total number of keys needed in symmetric cipher

Determine the total number of keys that are needed for organization if symmetric cipher is used.

  Create a java program to arithmetic expression

Create a Java program that takes as input an infix arithmetic expression then transforms to a postfix expression and based on binary tree, it evaluates that expression.

  Creating two single dimension arrays

Make two single dimension arrays that contain ten floating point numbers in each array. Make a third single dimension array to hold a sum.

  What is the machine run time in second for sorting array

Write computer program to implement this algorithm and demonstrate the results and what is the machine run time in second for sorting array A

  Creating a data flow chart

Create a Data Flow Chart and then make an application that allows a user to enter a stock transaction and determine the stockbroker's commission.

  Question about lan and wan

Think about the following two scenarios two computers are connected to a LAN using a total of 20-feet of cable, and two computers are connected over the Internet and are 8000 miles from each other.

  Devise a linear-time algorithm to count the parallel edges

Parallel edge detection: Devise a linear-time algorithm to count the parallel edges in a graph. Write the algorithm in pseudo-code.

  Computing time complexity of procedure

What is the time complexity of the procedure? If A[l .. r] = [24, 30, 09, 46, 15, 19, 29, 86,78], what is the output?

  Write algorithm to create job applicant report

Write the algorithm to create job applicant report. Input consists of a series of records that contain the Social Security number or equivalent, last name, first name, middle initial.

  2n-1 comparisons are necessary in the worst case

Prove that 2n-1 comparisons are necessary in the worst case to merge two sorted lists containing n elements each.

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