GATE 2020
64 questions
MCQ 41 · NAT 231-mark 29 · 2-mark 35
Questions 16–20 of 64
What is the worst case time complexity of inserting elements into an AVL-tree with n elements initially?
Answer: (C)
One AVL insertion takes time, with the size of the tree at that moment. The tree starts with elements and ends with , so always .
Upper bound: .
Lower bound: a tree with nodes has height at least about , and a worst-case insertion goes down to a deepest level, so it costs .
So each insertion costs in the worst case.
For insertions the total is .
Answer: (C)
Upper bound: .
Lower bound: a tree with nodes has height at least about , and a worst-case insertion goes down to a deepest level, so it costs .
So each insertion costs in the worst case.
For insertions the total is .
Answer: (C)
Consider the following statements.
I. If is regular, then both must be regular.
II. The class of regular languages is closed under infinite union.
Which of the above statements is/are TRUE?
I. If is regular, then both must be regular.
II. The class of regular languages is closed under infinite union.
Which of the above statements is/are TRUE?
Answer: (D)
Check each statement:
- I: let be any non-regular language and take . The union is , which is regular, yet is not regular so I is FALSE.
- II: every language is an infinite union of single strings, and each string is regular. If regular languages were closed under this, every language would be regular so II is FALSE.
Answer: Neither I nor II
- I: let be any non-regular language and take . The union is , which is regular, yet is not regular so I is FALSE.
- II: every language is an infinite union of single strings, and each string is regular. If regular languages were closed under this, every language would be regular so II is FALSE.
Answer: Neither I nor II
Consider the following statements.
I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
III. Errors violating the condition 'any variable must be declared before its use' are detected during syntax analysis.
Which of the above statements is/are TRUE?
I. Symbol table is accessed only during lexical analysis and syntax analysis.
II. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
III. Errors violating the condition 'any variable must be declared before its use' are detected during syntax analysis.
Which of the above statements is/are TRUE?
Answer: (D)
Let us check each statement:
- I: later phases also use the symbol table, such as semantic analysis and code generation FALSE.
- II: recursion needs a stack of activation records, and not a heap FALSE.
- III: the "declare before use" rule is a context-sensitive check made in semantic analysis FALSE.
Answer: None of I, II and III
- I: later phases also use the symbol table, such as semantic analysis and code generation FALSE.
- II: recursion needs a stack of activation records, and not a heap FALSE.
- III: the "declare before use" rule is a context-sensitive check made in semantic analysis FALSE.
Answer: None of I, II and III
Consider the language and the following statements.
I. L is deterministic context-free.
II. L is context-free but not deterministic context-free.
III. L is not LL(k) for any k.
Which of the above statements is/are TRUE?
I. L is deterministic context-free.
II. L is context-free but not deterministic context-free.
III. L is not LL(k) for any k.
Which of the above statements is/are TRUE?
Answer: (C)
Statements I and II. A DPDA pushes an a for each a it reads and accepts if the input ends there (the string is ). When it reads the first b, it starts popping one a per b, and accepts if the stack is empty at the end of the input. It never has to guess, so is a deterministic CFL. So I is true and II is false.
Statement III. For a large n, the inputs and have the same first n symbols. An LL(k) parser picks each production from the next k symbols only. Until it is within k symbols of the end of the a's, it sees only a's and so must make the same choices for both inputs, whatever grammar is used. It would then have about n pending symbols which must be matched with n b's for one input and all erased for the other, and k symbols of lookahead cannot make that choice for all of them. So is not LL(k) for any k. III is true.
Answer: (C)
Statement III. For a large n, the inputs and have the same first n symbols. An LL(k) parser picks each production from the next k symbols only. Until it is within k symbols of the end of the a's, it sees only a's and so must make the same choices for both inputs, whatever grammar is used. It would then have about n pending symbols which must be matched with n b's for one input and all erased for the other, and k symbols of lookahead cannot make that choice for all of them. So is not LL(k) for any k. III is true.
Answer: (C)
Consider allocation of memory to a new process. Assume that none of the existing holes in the memory will exactly fit the process's memory requirement. Hence, a new hole of smaller size will be created if allocation is made in any of the existing holes. Which one of the following statement is TRUE?
Answer: (C)
Best fit picks the smallest hole that can hold the process. So the hole it leaves is the smallest leftover possible. First fit picks some hole that fits, so the hole it leaves is never smaller than best fit's. So (C) is true.
The others are not always true:
- (A) If only one hole is big enough, first fit and next fit pick the same hole and leave equal holes, so first fit's is not larger.
- (B) If the largest hole comes first in the list, first fit picks it and worst fit picks it too, so the two holes are equal and worst fit's is not larger.
- (D) Take holes of 10 and 6 units (in this order), a process of 5 units, and a next fit search that starts at the 10 hole. Next fit leaves 5, but best fit uses the 6 hole and leaves 1. So next fit's hole is larger than best fit's.
Answer: (C)
The others are not always true:
- (A) If only one hole is big enough, first fit and next fit pick the same hole and leave equal holes, so first fit's is not larger.
- (B) If the largest hole comes first in the list, first fit picks it and worst fit picks it too, so the two holes are equal and worst fit's is not larger.
- (D) Take holes of 10 and 6 units (in this order), a process of 5 units, and a next fit search that starts at the 10 hole. Next fit leaves 5, but best fit uses the 6 hole and leaves 1. So next fit's hole is larger than best fit's.
Answer: (C)