GATE 2016 (Session 2)
65 questions
MCQ 38 · NAT 271-mark 30 · 2-mark 35
Questions 21–25 of 65
Breadth First Search(BFS) is started on a binary tree beginning from the root vertex. There is a vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the maximum possible value of n is______ .
Answer: 31
BFS goes through the tree one level at a time. To push t as late as possible in the order, fill levels 0 to 3 completely (1 + 2 + 4 + 8 = 15 nodes). Then let t be the last of the 16 nodes at level 4.
n = 15 + 16 = 31
Answer: 31
n = 15 + 16 = 31
Answer: 31
The value printed by the following program is .
void f(int*p, int m){
m =m+5;
*p =*p+m;
return;
}
void main(){
int i=5, j=10;
f(&i, j);
printf("%d", i+j);
}Answer: 30
m takes j's value: m = 10 + 5 = 15.
*p changes i: i = 5 + 15 = 20.
j is unchanged: 10.
Sum: i + j = 20 + 10 = 30
Answer: 30
*p changes i: i = 5 + 15 = 20.
j is unchanged: 10.
Sum: i + j = 20 + 10 = 30
Answer: 30
Assume that the algorithms considered here sort the input sequences in ascending order. If the input is already in ascending order, which of the following are TRUE?
I. Quicksort runs in time
II. Bubblesort runs in time
III. Merge sort runs in time
IV. Insertion sort runs in time
I. Quicksort runs in time
II. Bubblesort runs in time
III. Merge sort runs in time
IV. Insertion sort runs in time
Answer: (D)
When the input is already sorted:
- Quicksort (pivot is the first or last element) gets the most unbalanced splits . Statement I is True.
- Bubble sort with a "no swap" check ends after a single pass . Statement II is False.
- Merge sort always takes . Statement III is False.
- Insertion sort compares each element only once . Statement IV is True.
Answer: I and IV only
- Quicksort (pivot is the first or last element) gets the most unbalanced splits . Statement I is True.
- Bubble sort with a "no swap" check ends after a single pass . Statement II is False.
- Merge sort always takes . Statement III is False.
- Insertion sort compares each element only once . Statement IV is True.
Answer: I and IV only
The Floyd-Warshall algorithm for all-pair shortest paths computation is based on
Answer: (C)
The Floyd-Warshall algorithm works by using , and it reuses the answers of smaller subproblems. This is the dynamic programming approach.
Answer: Dynamic Programming paradigm
Answer: Dynamic Programming paradigm
N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided to the record to be deleted. For a decrease-key operation, a pointer is provided to the record on which the operation is to be performed.
An algorithm performs the following operations on the list in this order: , , , and . What is the time complexity of all these operations put together?
An algorithm performs the following operations on the list in this order: , , , and . What is the time complexity of all these operations put together?
Answer: (C)
The list is sorted and doubly linked. Delete and decrease-key are given a pointer to the node.
- delete: for one delete for all of them
- insert: first find the place, which takes for one insert
- find: for one find
- decrease-key: the node may need to move back towards the front, which takes for one operation
Total =
Answer:
- delete: for one delete for all of them
- insert: first find the place, which takes for one insert
- find: for one find
- decrease-key: the node may need to move back towards the front, which takes for one operation
Total =
Answer: