int exp(int X, int Y) {
int res = 1, a = X, b = Y;
while (b != 0) {
if (b % 2 == 0) { a = a * a; b = b / 2; }
else { res = res * a; b = b - 1; }
}
return res;
}Related Algorithms PYQs
Consider the directed acyclic graph with edges: a->b, b->c, c->f, a->d, d->e, e->f. The number of different topological orderings …
The worst case running times of Insertion sort, Merge sort and Quick sort, respectively, are:
Let G be a weighted connected undirected graph with distinct positive edge weights. If every edge weight is increased by the same …
Consider the weighted graph with distance matrix W: W = \[\begin{bmatrix}0 & 2 & 8 & 5\\2 & 0 & 5 & 8\\8 & 5 & 0 & x\\5 & 8 & x & …
Let G be a complete undirected graph on 4 vertices, having 6 edges with weights 1, 2, 3, 4, 5, and 6. The maximum possible weight …
G = (V, E) is an undirected simple graph with distinct edge weights, and e is a particular edge. Which statements about MSTs of G …
Free account benefits
Turn practice into measurable progress
Public PYQs and reference pages stay free. Sign in when you want GATEverse to remember what you studied and guide what to practise next.