GateAI
Graph Theory

GATE CSE 2016 Set 2 · Q41

MCQ2 marksMedium

Time

In an adjacency list representation of an undirected simple graph G=(V,E)G = (V, E), each edge (u,v)(u, v) has two adjacency list entries: [v][v] in the adjacency list of uu, and [u][u] in the adjacency list of vv. These are called twins of each other. A twin pointer is a pointer from an adjacency list entry to its twin. If ∣E∣=m|E| = m and ∣V∣=n|V| = n, and the memory size is not a constraint, what is the time complexity of the most efficient algorithm to set the twin pointer in each entry in each adjacency list?

Select one answerSingle correct

Pick an option to check

Solution

Step-by-step verified solution

Official answer: B) (n+m)

Graph Theory

There are 2m2m entries in total across all adjacency lists, where each entry represents a directed edge (u,v)(u, v) along with its memory address.

Since memory is not a constraint, we can pair each directed edge (u,v)(u, v) with its twin (v,u)(v, u) in linear time using Radix/Bucket Sort:

  1. Collect all 2m2m directed edges (u,v)(u, v) with a pointer to their corresponding list node.

  2. Sort these 2m2m pairs lexicographically using two passes of counting/bucket sort: first by destination vertex vv, then by source vertex uu. This takes O(n+m)O(n + m) time because vertex values are in the range [1,n][1, n].

  3. Similarly, canonical representations {min⁡(u,v),max⁡(u,v)}\{\min(u, v), \max(u, v)\} or direct lookup tables can be used to link twins in O(1)O(1) time per edge.

  4. Traversing the sorted list or using bucket-based grouping allows us to match each entry (u,v)(u, v) with (v,u)(v, u) in O(1)O(1) time per entry.

Hence, the overall time complexity of the most efficient algorithm is Θ(n+m)\Theta(n+m).

Therefore, the correct option is (B).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Graph Theory previous year question is Q41 of the GATE CSE 2016 Set 2 paper. Find more GATE CSE PYQs on Graph Theory in Programming and Data Structures, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 1 related Graph Theory PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Graph Theory in GATE CSE

GATE CSE 2016 Set 2 Q41 is the only Graph Theory question in the GATE CSE papers so far.

How GATE tests Graph Theory

More from GATE CSE 2016 Set 2

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2016 Set 2 · Q41 · MCQ

In an adjacency list representation of an undirected simple graph G = (V, E), each edge (u, v) has two adjacency list entries: [v] in the adjacency list of u, and [u] in the adjacency list of v. These are called twins of each other. A twin pointer is a pointer from an adjacency list entry to its twin. If |E| = m and |V| = n, and the memory size is not a constraint, what is the time complexity of the most efficient algorithm to set the twin pointer in each entry in each adjacency list?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.