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

  Write a program that checks if left and right braces

Write a program that checks if left and right braces, brackets, and parentheses are balanced

  Perform page trace analysis by fifo page removal algorithm

Using the FIFO page removal algorithm, do a page trace analysis indicating page faults with asterisks (*). Then compute the failure and success ratios.

  Write algorithm find intersection of two singly-linked list

Write an algorithm (pseudocode) to find the intersection of two singly-linked lists. Assume that the data in each list are in nondecreasing order.

  Let t be the degree of a btree

Let t be the degree of a BTree. Suppose the size of each object, including the key, stored in the tree is 90 bytes. Also, suppose the size of a BTreeNode pointer is 4 bytes.

  Relationships in a database model

Discuss different types of classifications and do they overlap, or do they each tell us something unique about the entity relationship?

  Creating an exception class and applet file

Create an applet document that prompts the user for an ID number and an age. Construct an Exception class and throw an Exception of that class if the ID is not in the range of valid ID numbers.

  Creating a class for services

Make a class for services offered by a hair styling salon. Information fields with a String to hold the service description, a double to hold the price, and an integer to hold average number of minutes it takes to perform the service.

  Choosing computer passwords

Before logging on to computer, you must have a unique username and unique password. Analyze and explain considerations you must make when choosing a password.

  Discussion on clustering and data mining

Clustering is generally used along with classification in some applications. In such a case, typically clustering is applied to a dataset to recognize natural grouping of the objects in the dataset,

  Program to create huffman codes

Write a C++ program to create Huffman codes. Program input is a file called freq.txt (make up your own file for testing) that contains data on the characters in some cleartext file in the form of each character's non-zero frequency of occurrence i..

  Write advantage of linked list implementation of stack

The tree's item type is int. Function must return number of leaves in tree. Determine the advantage of linked list implementation of stack versus array implementation?

  Professional codes of ethics

Select one of the Professional Codes of Ethics associated with IT. If you were to complete a assignment related to securing the connectivity in your firm and its business partners.

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