List of top Computer Science and IT Engineering Questions

Consider the following two syntax-directed definitions SDD1 and SDD2 for type
declarations.
𝐷 is the start symbol, and 𝑖𝑛𝑑, π‘“π‘™π‘œπ‘Žπ‘‘ and 𝑖𝑑 are the three terminals. The non-terminal
𝑉1 is the same as 𝑉 and the non-terminal 𝐷1 is the same as 𝐷. Here, the subscript is
used to differentiate the grammar symbols on the two sides of a production. The
function 𝑝𝑒𝑑 updates the symbol table with the type information for an identifier.
Let P and Q be the languages specified by grammars G1 and G2, respectively.
Which of the following statements is/are true?
SDD1
Grammar
(G1)
Semantic Rules
𝐷 →𝑇 𝑉
𝐷. 𝑑𝑦𝑝𝑒 = 𝑇. 𝑑𝑦𝑝𝑒
𝑉. 𝑑𝑦𝑝𝑒 = 𝑇. 𝑑𝑦𝑝𝑒
𝑇 β†’ 𝑖𝑛𝑑
𝑇. 𝑑𝑦𝑝𝑒 = 𝑖𝑛𝑑
𝑇 β†’ π‘“π‘™π‘œπ‘Žπ‘‘
𝑇. 𝑑𝑦𝑝𝑒 = π‘“π‘™π‘œπ‘Žπ‘‘
𝑉→𝑉1 𝑖𝑑
𝑉1. 𝑑𝑦𝑝𝑒= 𝑉. 𝑑𝑦𝑝𝑒
𝑝𝑒𝑑(𝑖𝑑. π‘’π‘›π‘‘π‘Ÿπ‘¦, 𝑉. 𝑑𝑦𝑝𝑒)
𝑉 β†’ 𝑖𝑑
𝑝𝑒𝑑(𝑖𝑑. π‘’π‘›π‘‘π‘Ÿπ‘¦, 𝑉. 𝑑𝑦𝑝𝑒)
SDD2
Grammar
(G2)
Semantic Rules
𝐷→𝐷1 𝑖𝑑
𝐷. 𝑑𝑦𝑝𝑒= 𝐷1. 𝑑𝑦𝑝𝑒
𝑝𝑒𝑑(𝑖𝑑. π‘’π‘›π‘‘π‘Ÿπ‘¦, 𝐷1. 𝑑𝑦𝑝𝑒)
𝐷 β†’ 𝑇 𝑖𝑑
𝐷. 𝑑𝑦𝑝𝑒 = 𝑇. 𝑑𝑦𝑝𝑒
𝑝𝑒𝑑(𝑖𝑑. π‘’π‘›π‘‘π‘Ÿπ‘¦, 𝑇. 𝑑𝑦𝑝𝑒)
𝑇 →𝑖𝑛𝑑
𝑇. 𝑑𝑦𝑝𝑒 = 𝑖𝑛𝑑
𝑇 β†’ π‘“π‘™π‘œπ‘Žπ‘‘
𝑇. 𝑑𝑦𝑝𝑒 = π‘“π‘™π‘œπ‘Žπ‘‘

Consider the following pseudocode for depth-first search (DFS) algorithm which
takes a directed graph 𝐺(𝑉, 𝐸) as input, where 𝑑[𝑣] and 𝑓[𝑣] are the discovery time
and finishing time, respectively, of the vertex 𝑣 βˆˆπ‘‰.
𝐷𝐹𝑆(𝐺):
π‘’π‘›π‘šπ‘Žπ‘Ÿπ‘˜ π‘Žπ‘™π‘™ π‘£βˆˆπ‘‰
𝑑 ←0
π‘“π‘œπ‘Ÿ π‘’π‘Žπ‘β„Ž π‘£βˆˆπ‘‰
𝑖𝑓 𝑣 𝑖𝑠 π‘’π‘›π‘šπ‘Žπ‘Ÿπ‘˜π‘’π‘‘
𝑑←𝐸π‘₯π‘π‘™π‘œπ‘Ÿπ‘’(𝐺, 𝑣, 𝑑)
𝑒𝑛𝑑 𝑖𝑓
𝑒𝑛𝑑 π‘“π‘œπ‘Ÿ
𝐸π‘₯π‘π‘™π‘œπ‘Ÿπ‘’(𝐺, 𝑣, 𝑑):
π‘šπ‘Žπ‘Ÿπ‘˜ 𝑣
𝑑 ←𝑑+ 1
𝑑[𝑣] ←𝑑
π‘“π‘œπ‘Ÿ π‘’π‘Žπ‘β„Ž (𝑣, 𝑀) ∈𝐸
𝑖𝑓 𝑀 𝑖𝑠 π‘’π‘›π‘šπ‘Žπ‘Ÿπ‘˜π‘’π‘‘
𝑑←𝐸π‘₯π‘π‘™π‘œπ‘Ÿπ‘’(𝐺, 𝑀, 𝑑)
𝑒𝑛𝑑 𝑖𝑓
𝑒𝑛𝑑 π‘“π‘œπ‘Ÿ
𝑑 ←𝑑 + 1
𝑓[𝑣] ←𝑑
π‘Ÿπ‘’π‘‘π‘’π‘Ÿπ‘› 𝑑
Suppose that the input directed graph 𝐺(𝑉, 𝐸) is a directed acyclic graph (DAG).
For an edge (𝑒, 𝑣) ∈𝐸, which of the following options will NEVER be correct?