GATE 2023
65 questions
MCQ 34 · MSQ 15 · NAT 161-mark 30 · 2-mark 35
Questions 46–50 of 65
Let A be a priority queue for maintaining a set of elements. Suppose A is implemented using a max-heap data structure. The operation Extract-Max(A) extracts and deletes the maximum element from A. The operation Insert(A,key) inserts a new element key in A. The properties of a max-heap are preserved at the end of each of these operations.
When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?
When A contains n elements, which one of the following statements about the worst case running time of these two operations is TRUE?
Answer: (B)
A heap with n elements has a height of about log n.
- Extract-Max: take out the root, put the last element at the root, then heapify down along the height of the tree .
- Insert: put the new element at the end, then bubble it up toward the root .
Answer: Both run in O(log(n))
- Extract-Max: take out the root, put the last element at the root, then heapify down along the height of the tree .
- Insert: put the new element at the end, then bubble it up toward the root .
Answer: Both run in O(log(n))
Consider the C function foo and the binary tree shown.
When foo is called with a pointer to the root node of the given binary tree, what will it print?
typedef struct node {
int val;
struct node *left, *right;
} node;
int foo(node *p) {
int retval;
if (p == NULL)
return 0;
else {
retval = p->val + foo(p->left) + foo(p->right);
printf("%d ", retval);
return retval;
}
}
When foo is called with a pointer to the root node of the given binary tree, what will it print?
Answer: (C)
The function gives back the sum of a subtree. It prints that sum after it has visited both children, so the order is post-order:
- Node 3 prints 3
- Node 8 prints 8
- Node 5 gives 5 + 3 + 8 = 16
- Node 13 prints 13
- Node 11 gives 11 + 0 + 13 = 24
- Root 10 gives 10 + 16 + 24 = 50
Answer: 3 8 16 13 24 50
- Node 3 prints 3
- Node 8 prints 8
- Node 5 gives 5 + 3 + 8 = 16
- Node 13 prints 13
- Node 11 gives 11 + 0 + 13 = 24
- Root 10 gives 10 + 16 + 24 = 50
Answer: 3 8 16 13 24 50
Let U = {1, 2,...,n}, where n is a large positive integer greater than 1000. Let k be a positive integer less than n. Let A, B be subsets of U with |A| = |B| = k and . We say that a permutation of U separates A from B if one of the following is true.
- All members of A appear in the permutation before any of the members of B.
- All members of B appear in the permutation before any of the members of A.
How many permutations of U separate A from B?
- All members of A appear in the permutation before any of the members of B.
- All members of B appear in the permutation before any of the members of A.
How many permutations of U separate A from B?
Answer: (D)
Count the permutations in these steps:
- Pick the 2k positions that the elements of A B will take: ways
- Place the remaining elements in the other positions: ways
- In the 2k chosen positions, either all of A come first and then B, or all of B come first and then A: 2 ways
- Order A within its k places and order B within its k places: ways
Total count
Answer:
- Pick the 2k positions that the elements of A B will take: ways
- Place the remaining elements in the other positions: ways
- In the 2k chosen positions, either all of A come first and then B, or all of B come first and then A: 2 ways
- Order A within its k places and order B within its k places: ways
Total count
Answer:
Let be an onto (or surjective) function, where and are nonempty sets. Define an equivalence relation on the set as
where . Let be the set of all the equivalence classes under . Define a new mapping as
for all the equivalence classes in
Which of the following statements is/are TRUE?
where . Let be the set of all the equivalence classes under . Define a new mapping as
for all the equivalence classes in
Which of the following statements is/are TRUE?
One or more options are correct.
Answer: (B), (C), (D)
Test F for each property.
- Well-defined: suppose . Then , so . So F gives one value whichever representative we pick, and (A) is FALSE.
- Onto: take any . Since f is onto, some has . Then , so (B) is TRUE.
- One-to-one: suppose . Then , so and . So (C) is TRUE.
- F is onto and one-to-one, so it is bijective, and (D) is TRUE.
Answer: (B), (C), (D)
- Well-defined: suppose . Then , so . So F gives one value whichever representative we pick, and (A) is FALSE.
- Onto: take any . Since f is onto, some has . Then , so (B) is TRUE.
- One-to-one: suppose . Then , so and . So (C) is TRUE.
- F is onto and one-to-one, so it is bijective, and (D) is TRUE.
Answer: (B), (C), (D)
Suppose you are asked to design a new reliable byte-stream transport protocol like TCP. This protocol, named myTCP, runs over a 100 Mbps network with Round Trip Time of 150 milliseconds and the maximum segment lifetime of 2 minutes.
Which of the following is/are valid lengths of the Sequence Number field in the myTCP header?
Which of the following is/are valid lengths of the Sequence Number field in the myTCP header?
One or more options are correct.
Answer: (B), (C), (D)
Sequence numbers must not repeat (wrap around) within one MSL. Count the bytes sent in 2 minutes:
bytes
Compare with the sequence space: (too small), (big enough). So the field needs at least 31 bits.
Valid lengths are 32, 34 and 36 bits. 30 bits is not valid.
Answer: 32 bits, 34 bits, 36 bits
bytes
Compare with the sequence space: (too small), (big enough). So the field needs at least 31 bits.
Valid lengths are 32, 34 and 36 bits. 30 bits is not valid.
Answer: 32 bits, 34 bits, 36 bits