

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Professor: Schmidt; Class: Computer Science Foundations; Subject: Computer Science; University: Drexel University; Term: Unknown 1989;
Typology: Study notes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


This solution differs a bit from the one provided earlier; that solution inducted over the # of productions applied, rather than the height of the expression tree. They are very similar, however.
We are to show that the following grammar generates the balanced profile strings, as defined in section 2.6:
We will use induction, on the height of the expression tree that produces strings s Є L(
Our base case is simple. We have only one possible tree of height one:
Trivially, ε (the empty , or null string) is balanced. So, by the inductive hypothesis, we may assume that any such tree of height <= n produces a profile-balanced string.
Section 2.6 defines a profile-balanced string s so: Set ctr=0 , scan s from left to right. For each character ‘(‘ that is encountered, increment ctr. For each ‘)’ that is encountered, decrement ctr. If, and only if, after the entire string s is scanned, ctr is 0, and it at no time was negative, then s is profile-balanced.
We now need to show that any string, s’ , represented by an expression tree of height n+1 is also balanced. There are 2 productions in the grammar that allow us to build on existing expressions. Lets consider:
Represented:
If the tree rooted at the red node has height n+1, then the 2 (blue and green) have height <= n, so, by our hypothesis, s 1 and s 2 are profile balanced. We need to show that the string s’ =s 1 s 2 is profile balanced. Start on the left, ctr = 0. After we scan s 1 ctr is 0, and was never negative.
s 1 s (^2)
ε
We then scan s 2 , and again, (by our hypothesis) ctr is 0, and was never negative. We scanned s’ , ctr is 0, and was never negative, so, by the definition from 2.6, s’ is profile balanced.
We have another possible tree of height n+1 that we need to consider, given to us by the production:
We need to show that s’ = ( s ) is profile balanced. Same game. ctr = 0, start at the left, ‘(‘. ctr = 1. By the hypothesis s is balanced, so after parsing it ctr is still 1, and, further, was never less than 1 (specifically, was never negative). Hit that last ‘)’, ctr is back to 0. By definition, s’ is profile balanced. Done.
I can offer no improvement over the solution previously provided.
Show that any profile-balanced string, s , is an element of L(
We will induct over the length of s. We are using strong induction. We need to get away from the n, n+1 thing, it’ll bog us down (since, think about it, parenthesis need to be added in pairs).
We start with ε, a balanced string of length 0. We verify that it is in L(
We use the definition from 2.6, our ctr , from above. Start it at 0. When we’re done we know ctr is 0. We have 2 cases to consider:
You simply need to verify that, in each case, the grammar takes a valid string (or strings) and can produce s , of length n.
s