Question
Problem 1: Nested List Sets We have a special type of set where the syntax is depicted by the following grammar: Set := { Elementlist
Problem 1: Nested List Sets We have a special type of set where the syntax is depicted by the following grammar: Set := "{" Elementlist "}" Elementlist := | List List := Element | Element "," List Element := Atom | Set Atom := "{" | "}" | "," stands for the empty word, i.e., the list in a set can be empty. Note the alphabet consists of the characters which are also used for the syntax of the set. At first thought one may think that it is not possible to decide efficiently if a word consisting of {, } and , is a syntactically correct representation of a set or not. However, using dynamic programming design techniques, your task is to write an efficient program that will decide this problem. Input Specification The first line of the input file contains a number representing the number of lines to follow. Each line consists of a word, for which your program has to decide if it is a syntactically correct representation of a set. You may assume that each word consists of between 1 and 300 characters from the set { {, }, , }. Output Specification Output for each test case whether the word is a set or not. Adhere to the format shown in the sample output. Sample Input 4 {} {{}} {{}},{,}} {,,} Sample Output Word #1: Set 1 Word #2: Set Word #3: Set Word #4: No Set
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started