New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

FoCS Exam #2 Study Guide

by: thersh

FoCS Exam #2 Study Guide CSCI 2200


Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Study guide for second FoCS Exam - Context-Free Languages Unit
Foundations of Computer Science
Petros Drineas
Study Guide
50 ?




Popular in Foundations of Computer Science

Popular in ComputerScienence

This 44 page Study Guide was uploaded by thersh on Monday May 2, 2016. The Study Guide belongs to CSCI 2200 at Rensselaer Polytechnic Institute taught by Petros Drineas in Spring 2016. Since its upload, it has received 29 views. For similar materials see Foundations of Computer Science in ComputerScienence at Rensselaer Polytechnic Institute.

Similar to CSCI 2200 at RPI

Popular in ComputerScienence


Reviews for FoCS Exam #2 Study Guide


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 05/02/16
Context-Free Languages {a b :n  0} {ww }R Regular Languages a*b* (a b)* Context-Free Languages n n {ww } {a b } Regular Languages Context-Free Languages Context-Free Pushdown Grammars Automata stack automaton Context-Free Grammars Grammars Grammars express languages Example: the English language sentence  noun_ phrase predicate noun_ phrase  article noun predicate  verb article  a article the noun  cat noun  dog verb  runs verb  walks A derivation of “the dog walks”: sentence  noun_ phrase predicate  noun_ phrase verb  article noun verb  the noun verb  the dog verb  the dog walks A derivation of “a cat runs”: sentence  noun_ phrase predicate  noun_ phrase verb  article noun verb  a noun verb  a cat verb  a cat runs Language of the grammar: L = { “a cat runs”, “a cat walks”, “the cat runs”, “the cat walks”, “a dog runs”, “a dog walks”, “the dog runs”, “the dog walks” } Notation Production Rules noun  cat noun  dog Variable Terminal Another Example Grammar: S  aSb S   Derivation of sentenceab : S  aSb  ab S  aSb S   Grammar: S  aSb S   Derivation of sentence aabb : S  aSb  aaSbb  aabb S  aSb S   Other derivations: S  aSb  aaSbb  aaaSbbb  aaabbb S  aSb  aaSbb  aaaSbbb  aaaaSbbbb  aaaabbbb Language of the grammar S  aSb S   n n L {a b :n  0} More Notation Grammar G  V,T,S,P  V : Set of variables T : Set of terminal symbols S : Start variable P: Set of Production rules Example Grammar G : S  aSb S   G  V,T,S,P  V {S} T {a,b} P {S  aSb, S  } * We write: S  aaabbb Instead of: S  aSb  aaSbb  aaaSbbb  aaabbb * In general we write: w1 w n If: w 1 w  2  3 n * By default: w  w Example Grammar Derivations S  aSb * S S   * Sab * Saabb * Saaabbb Another Grammar Example GrammarG : S  Ab A aAb A  Derivations: S⇒Ab⇒ b S⇒Ab⇒ aAbb⇒ abb S⇒Ab⇒ aAbb⇒ aaAbbb⇒ aabbb More Derivations S  Ab  aAbb  aaAbbb  aaaAbbbb  aaaaAbbbbb  aaaabbbbb  Saaaabbbbb  Saaaaaabbbbbbb  n n Sa b b Language of a Grammar For a grammar G with start variable :  L(G) {w: Sw} String of terminals Example For grammar G : S  Ab A aAb A  L(G) {a b b: n  0}  n n Since: Sa b b A Convenient Notation A aAb A  A aAb| S  aSb S   L(G)  {a b :n  0} Describes parentheses: (((( )))) Example A context-free grammarG : S  aSa S bSb S   A derivation: S  aSa  abSba  abba A context-free grammarG : S  aSa S bSb S   Another derivation: S  aSa  abSba  abaSaba  abaaba S  aSa S bSb S   L(G)  {ww : w{a,b}*} Definition: Context-Free Grammars Grammar G  (V,T,S,P) Variables Terminal Start symbols variable Productions of the form: A x Variable String of variables and terminals Definition: Context-Free Languages A language L is context-free if and only if there is a context-free grammarG with L  L(G) Derivation Order 1. S  AB 2. A aaA 4. B  Bb 3. A  5. B   Leftmost derivation: 1 2 3 4 5 S ABaaABaaBaaBbaab Rightmost derivation: 1 4 5 2 3 S AB ABb AbaaAbaab S  aAB AbBb B  A| Leftmost derivation: S  aAB  abBbB  abAbB  abbBbbB  abbbbB  abbbb Rightmost derivation: S  aAB  aA abBb  abAb  abbBbb  abbbb Ambiguity E  E  E | EE | (E) | a a  aa E  E  E  a  E  a  EE  a aE  a  a*a leftmost derivation E  E  E | EE | (E) | a a  aa E  EE  E  EE  a  EE  a  aE  a  aa leftmost derivation The grammar E  E  E | EE | (E) | a isambiguous: stringa  aa has two leftmost derivations E  E  E  a  E  a  EE  a  aE  a  a*a E  EE  E  EE  a  EE  a  aE  a  aa Definition: A context-free grammar G is ambiguous if some stringwL(G) has: two or more leftmost derivations (or rightmost) • Ambiguity is bad for programming languages It leads to two or more alternative ways to parse statements. This is a disaster for compilers, since they do not know how to resolve such ambiguities. • We want to remove ambiguity Inherent Ambiguity Some context free languages have only ambiguous grammars Example: L {a b c }  {a b c } m S  S 1 S2 S1 S c1 A S2 aS |2B A aAb| B bBc| n n n Fact: The language {a b c } is not context-free (This can be can proven using a pumping lemma for context-free languages) The Language Hierarchy a b cn ? ww ? Context-Free Languages n n a b ww R Regular Languages a* a*b* Languages accepted by Turing Machines n n n ww a b c Context-Free Languages a b n R ww Regular Languages a* a*b*


Buy Material

Are you sure you want to buy this material for

50 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Amaris Trozzo George Washington University

"I made $350 in just two days after posting my first study guide."

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.