GATE 2026
65 questions
MCQ 33 · MSQ 14 · NAT 181-mark 30 · 2-mark 35
Questions 16–20 of 65
Consider the given Python program.
def append_to_lst(val, lst=[]):
lst.append(val)
return lst
print(append_to_lst(1))
print(append_to_lst(2))
print(append_to_lst(3, [])) Which of the following is the correct output of this program?Answer: (B)
Python has a known trap with a mutable default argument. A default value (like ) is created once, when the function is defined. It is reused in every call that does not pass its own argument for it, so it is not reset to a fresh empty list on each call.
- : no list is passed, so the call uses (and changes) the shared default list. It becomes and is printed as .
- : again no list is passed, so it reuses the same shared default list, which still holds from before, and then appends . It becomes and is printed as .
- : this call passes a brand-new, separate empty list, so the shared default does not affect it. It becomes and is printed as .
Answer: [1], [1,2], [3]
- : no list is passed, so the call uses (and changes) the shared default list. It becomes and is printed as .
- : again no list is passed, so it reuses the same shared default list, which still holds from before, and then appends . It becomes and is printed as .
- : this call passes a brand-new, separate empty list, so the shared default does not affect it. It becomes and is printed as .
Answer: [1], [1,2], [3]
Let be a relational schema with functional dependency set .
Which of the following statements is correct?
Which of the following statements is correct?
Answer: (A)
Given with .
does not appear on the right side of any dependency, so no other attribute can give . So every candidate key must contain , and is not enough on its own.
Now try with one more attribute:
: gives . Then gives all 5 attributes. is a key.
: gives . Then gives all 5. is a key.
: gives . Then and give all 5. is a key.
, since determines nothing. So is not a key.
All these keys have two attributes and are minimal, because neither alone nor a single other attribute is a key. Any other key must contain plus at least one more attribute. If that attribute is , or , the set contains one of and is not minimal. If it is only , it is (or a superset that has and only), which is not a key. So the only candidate keys are .
Answer: (A)
does not appear on the right side of any dependency, so no other attribute can give . So every candidate key must contain , and is not enough on its own.
Now try with one more attribute:
: gives . Then gives all 5 attributes. is a key.
: gives . Then gives all 5. is a key.
: gives . Then and give all 5. is a key.
, since determines nothing. So is not a key.
All these keys have two attributes and are minimal, because neither alone nor a single other attribute is a key. Any other key must contain plus at least one more attribute. If that attribute is , or , the set contains one of and is not minimal. If it is only , it is (or a superset that has and only), which is not a key. So the only candidate keys are .
Answer: (A)
Consider that the visualization of a -dimensional data cube is showing Sales Quantity for each combination of the attributes Product Type, Month and Country.
From this, if we want to further visualize the Sales Quantity for each combination of Product Type, Month and State, which of the following OLAP operations should be performed?
From this, if we want to further visualize the Sales Quantity for each combination of Product Type, Month and State, which of the following OLAP operations should be performed?
Answer: (D)
The data cube has the dimensions Product Type, Month and Country. We want Country replaced by State. State is a finer level of the location hierarchy (), so the data is shown in more detail. Product Type and Month stay the same.
Going down to a finer level of a hierarchy is drill-down.
Why the others do not fit:
Roll-up is the opposite, from State up to Country.
Slicing fixes one dimension at a single value, and dicing picks a sub-cube. Neither adds a finer level.
Answer: (D)
Going down to a finer level of a hierarchy is drill-down.
Why the others do not fit:
Roll-up is the opposite, from State up to Country.
Slicing fixes one dimension at a single value, and dicing picks a sub-cube. Neither adds a finer level.
Answer: (D)
Let be a randomly chosen non-empty subset of .
Which of the following is the probability that the product of all the elements of is even?
Which of the following is the probability that the product of all the elements of is even?
Answer: (C)
In the set , there are exactly odd numbers and even numbers. The product of the elements of is even unless all the chosen elements are odd.
Number of non-empty subsets of : . Number of non-empty subsets made only of odd numbers: (any non-empty subset of the odd numbers).
Answer:
Number of non-empty subsets of : . Number of non-empty subsets made only of odd numbers: (any non-empty subset of the odd numbers).
Answer:
Suppose that a computer program provides a non-negative and integer-valued random solution to the equation .
Which of the following is the probability that all of in the provided solution are positive?
Which of the following is the probability that all of in the provided solution are positive?
Answer: (A)
Count all non-negative integer solutions of using stars and bars:
Now count the solutions where every holds (all positive). Put . Then , which gives such solutions.
Assume the "random solution" is picked uniformly from all non-negative solutions. Then the probability that all are positive is:
Answer: C(19,3)/C(23,3)
Now count the solutions where every holds (all positive). Put . Then , which gives such solutions.
Assume the "random solution" is picked uniformly from all non-negative solutions. Then the probability that all are positive is:
Answer: C(19,3)/C(23,3)